Having trouble with proper regex for RewriteCond
RewriteCond %{REQUEST_URI} !^/foo/
Works as expected, that is, does not apply following rewrite to all URLs that start with /foo/.
RewriteCond %{REQUEST_URI} !^/foo/bar/
On the other hand does not work as I expect. URLs that begin with /foo/bar/ are still being rewrited.
How do I enter proper regex for excluding subdirectories?
Maybe it’s the new URL of an internal redirect the rule is applied to. The L
flag does that.
[…] if the
RewriteRule
generates an internal redirect (which frequently occurs when rewriting in a per-directory context), this will reinject the request and will cause processing to be repeated starting from the firstRewriteRule
.
If you want to make sure that the initial URL path didn’t start with „/foo/bar“, check the request line (see THE_REQUEST
variable) instead:
RewriteCond %{THE_REQUEST} !^[A-Z]+\ /foo/bar/
RewriteRule …
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With