I am building a LAMP application www.testing.com
and I have an image url www.testing.com/image/folderA/a.jpg
.
I want to have a rewrite rule in .htacess such that if user navigates to images that do not exist in /image/foldera, he will be redirected to another image with the url www.testing.com/image/folderB/b.jpg
.
This is my code.
RewriteRule ^image/folderA/(.*\.(jpg|gif|png))$ http://%{SERVER_NAME}/image/folderB/b.jpg [R=404,L]
However, this is not working as www.testing.com/image/folderA/a.jpg
, which is supposed to return an image, gives an 404. Any idea why?
When using the R flag you need to keep the following in mind:
However, if a status code is outside the redirect range (300-399) then the substitution string is dropped entirely, and rewriting is stopped as if the L were used.
http://httpd.apache.org/docs/trunk/rewrite/flags.html#flag_r
This means that your rewrite rule is dropping the substition string and redirecting all requests to specified files to the built-in 404 page.