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

Fixed a regression introduced by 28efafa24c.
Thanks Michal Čihař for the report and initial patch.
Would os.path.normpath() be better here? It seems to remove the trailing slash.