I don't know if this is possible or not, I have an image host that I've made myself. I need some last tweaks with it.
Whenever an image has been deleted or is an invalid image url, it should replace with an 404 image, so for example if someone adds this:
But it's an invalid link, so I need it to show:
Which is like this:
alt text http://tinypic.com/images/404.gif
I do know that .htaccess
can do this with it's ErrorDocument 404
, but I have one already when a user access to an invalid page, so it would show the 404 page.
So whenever a user hotlinks an image and it's invalid or is deleted, I need it to be replaced with the 404 image.
How can I make this?
With Apache, you can have multiple .htaccess files. So, if all of your images are stored in the same directory, create an
.htaccess
file inside of that directory and addThis will create a custom 404 redirect that is applied only to your image directory, plus its subdirectories.
According and in addition to AdamH's answer, you should output
404 header
. Here's what I'm using,.htaccess
image404.php
Here's one potential answer:
Another is to use a custom scripted page:
http://www.webmasterworld.com/forum92/3458.htm
You can use ErrorDocument with FilesMatch directive
This will show /image.jpg if a 404 image uri with jpg png or gif extension is requested.
you can also add your custom image or html markup to the errordocument :