views:

523

answers:

1

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?

+1  A: 

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 …
Gumbo
Don't know how and why but this works
edgars