Forum Moderators: phranque
I am trying to redirect all images on my site that will return a 404 not found error to a generic not found image. I would also like to parse the size out. For example if someone visits my site and accesses an image http://example.com/image/albert/abc_74x74.jpg and it does not exist then I would like it to redirect to http://example.com/images/unknown_74x74.jpg
If it is a *_125x60.jpg and not found then it should map to http://example.com/images/unknown_125x60.jpg etc.
I got the RewriteRule part of it to work but not sure how to put the [OR] statement in for the other image sizes. I also cannot get the RewriteCond to work. For the condition I would like it to say 'if the url is a 404 not found'.
Here is what I have so far....
RewriteCond %{REQUEST_URI} !-U
RewriteRule ^(.+)_74x74\.jpg$ http://example.com/images/unknown_74x74.jpg [NC,L]
Any suggestions or help? Thanks a bunch.
Alantyss
[edited by: jdMorgan at 4:10 pm (utc) on Mar. 27, 2008]
[edit reason] example.com [/edit]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^image/[^/]+/[^_]+_([0-9]+x[0-9]+)\.jpg$ http://example.com/images/unknown_$1.jpg [R=301,L]
If the code is to be located in the "/image" directory, then remove that part of the path from the RewriteRule pattern, but leave "/images" in the substitution URL.
Consider carefully the fact that you will no longer get 404 error entries in your logs for missing images, and will instead have to track down missing images by looking for these redirects in your logs. Depending on the size of your site, this may significantly increase the work needed to maintain a quality site.
Jim