Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to match subdirectories in RewriteCond?

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?

like image 714
edgars Avatar asked May 08 '09 12:05

edgars


1 Answers

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 first RewriteRule.

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 …
like image 52
Gumbo Avatar answered Nov 07 '22 05:11

Gumbo