Adapt an Apache mod_rewrite RewriteRule not to act on physical directories
-
02-07-2019 - |
Question
I have this RewriteRule that works too well :-)
RewriteRule ^([^/]*)/$ /script.html?id=$1 [L]
The bad thing about this rule is that it also matches physical directories which I don't want.
How can I tell the mod_rewrite
to ignore physical directories and apply the above rule only when the directory matched does not exist?
Solution
Take a look at RewriteCond. Put the following before your rule to exempt out directories and files
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
OTHER TIPS
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]*)/$ /script.html?id=$1 [L]
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow