How do I write a mod_rewrite rule to search for an image in a specific folder?
I need to write a rule to redirect any image file to a specific folder. Namely "images"
RewriteCond $1 ^(.*\.jpg|.*\.gif|.*\.bmp)
It will fit all imagination, the rewrite part is baffling me. I want to
Http://domain.com/path/controller/view/image.jpg
http://domain.com/any/path/that/i/want/image.jpg
to download the file
http://domain.com/iamges/image.jpg
Is it possible?
+1
source to share
1 answer
RewriteEngine On
RewriteBase /
# prevent endless loops
RewriteCond %{REQUEST_URI} !images/
# capture only the filename
RewriteRule ^.*/(.*\.jpg|.*\.gif|.*\.bmp) images/$1 [L,R]
The R option to [L, R] forces the visible overwrite - if you want the image to appear on the prompt screen, just use [L]
Have a look at the mod_rewrite documentation for more details
+2
source to share