3

I've got a product gallery I'm working on and just did an import. This added a bunch of references to images that don't exist on the server.

Right now when the image tries to load, it's got that broken image icon, which is ugly, and well, should be handled better.

Ideally, whenever a broken image would be displayed -- that is to say when an image's path just doesn't exist -- I would like Apache to show a placeholder image instead.

Is there any way to do this via .htaccess?

WNRosenberg
  • 1,862
  • 5
  • 22
  • 31

1 Answers1

4

Use RewriteCond with -f to check if the file exists, e.g.:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^.*(\.gif|\.jpe?g|\.png)$ placeholder.jpg [L]