Fixed #23583 -- More selectively ignored static/media roots

Fixed a regression introduced by 28efafa24c.
Thanks Michal Čihař for the report and initial patch.