Wednesday, May 27, 2009

Apache: "Redirecting" Missing Images with a Default Image

We all know how horrible sites with broken image links are. If you maintain a lot of sites, you can't give your attention to each and every image detail on every site. So what about displaying a default image instead when an image is missing? Well, that will work perfectly fine as long as the images are stored on your server and are not external image links; and this is real simple to do with Apache's mod_rewrite!

Try this code in your vhost entry:

RewriteEngine On
RewriteCond "%{DOCUMENT_ROOT}%{REQUEST_URI}" !-f
RewriteRule \.(gif|jpe?g|png|bmp) /path/to/your/404.gif [NC,L]


Cheers!

Note: This idea was found on the web. At the time of this writing, I cannot find the original source. But if I do, I will properly credit them!

Update A forum link was found as a reference:http://www.webmasterworld.com/apache/3274493.htm

2 comments:

supareno said...

found a reference here: http://www.webmasterworld.com/apache/3274493.htm.
thaks for the tip, i will use it tomorrow :-)

Unknown said...

supareno, thank you kindly. a reference for us all! cheers!