2

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

chrisK
  • 61
  • 1
  • 1
  • 9

3 Answers3

4

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/(.*)$
Mike
  • 598
  • 7
  • 16
2

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.

Rich Bowen
  • 171
  • 2
0

you should just remove ^ from your command. try this:

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