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?



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/(.*)$
| improve this answer | |
  • Doesn't work :( – chrisK Jul 7 '13 at 13:30

Mike's answer is correct. Consider turning on the RewriteLog to observe what mod_rewrite is actually doing. This will give you much better insight into what your rules should actually look like.

Also, putting (.*)$ on the end of a RewriteCond is unnecessary and inefficient unless you're actually planning to use the value of %1 in a later RewriteRule.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.