RewriteCond RequestURI why RegEx doesn’t work

mod-rewriteregular expressions

i have a working RewriteCond like:

RequestURL:
http://www.myserver.com/images/gallery/summer/2013/2013-07-07/thumbs/001.jpg

RewriteCond %{REQUEST_URI} !images/gallery/summer/2013/*
RewriteRule ^images/gallery/summer/(.*)$ http://xyz.s3.amazonaws.com/$1 [P]

This works fine and the image is pulled from Amazon S3.

But why the heck a RegEx doesn't work in the RewriteCond like:

RewriteCond %{REQUEST_URI} !^images/gallery/summer/2013/(.*)$

It's just i want to understand why the above code works and the other doesn't?

THANK YOU

Best Answer

REQUEST_URI begins with /, so instead of this one:

RewriteCond %{REQUEST_URI} !^images/gallery/summer/2013/(.*)$

try this:

RewriteCond %{REQUEST_URI} !^/images/gallery/summer/2013/(.*)$
Related Topic