Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I'm trying to make the following kind of mapping from URL to file system for image files only:

mysite.com/image.jpg  ->  images/image.jpg
mysite.com/folder/other.jpg  ->  images/folder/other.jpg
mysite.com/x/y/z.jpg  ->  images/x/y/z.jpg

I've tried the following, but it apparently causes an infinite redirect loop:

RewriteRule ^(.*\.(gif|jpg|png))$ images/$1 [QSA,L]

Any mod_rewrite gurus here?

share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

Just add a condition before your rule to see if it has already been rewritten to images/

RewriteCond %{REQUEST_URI} !/images/.*
RewriteRule ^(.*\.(gif|jpg|png))$ images/$1 [QSA,L]
share|improve this answer
    
I would suggest the QSA flag could likely be removed as it's unlikely you'll have a query string following the image URI. –  Jeremy Bouse Sep 3 '09 at 19:49
    
Thanks, it works that way! Also, the QSA flag was unnecessary. –  Joonas Pulakka Sep 4 '09 at 3:55
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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