views:

127

answers:

1

I need to write a rule to redirect any image file to a specific folder. Namely "images"

RewriteCond $1 ^(.*\.jpg|.*\.gif|.*\.bmp)

That will match all the imag, the the rerwrite part is confusing me. I want that

Http://domain.com/path/controller/view/image.jpg
http://domain.com/any/path/that/i/want/image.jpg

to load the file

http://domain.com/iamges/image.jpg

Is this possible?

+2  A: 
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 in the [L,R] is forcing a visible rewrite - if you want it to appear that the image is coming from the request url then just use [L]

Take a look at the mod_rewrite documentation for more details

Ken
thanks a lot man..I actually got something along the same line.. but the prevent endless lopp part that is causing me some problems( i don't have it ).. and your example solved my problem...
paan