404 error for image: can I display an error image?

Is there a way to let apache serve a custom error image when an image is requested that does not exist on the server?
LVL 1
grexxAsked:
Who is Participating?
 
wesly_chenCommented:
Hi,
   You can redirect to a PERL/CGI script as follow:
------
ErrorDocument 404 /errors/custom404.cgi
-----
   Then in the CGI script, check the page extention (jpg, gif, or html)
and redirect to different 404 error message page. (404image.html and 404general.html)

   And you customize the those pages (404image.html and 404general.html).

Wesly
0
 
Diablo84Commented:
You can handle this with HTML if this is an option, eg:

<img src="animage.jpg" onerror="this.src='error_image.jpg'">

If the first image cannot be loaded the later will be loaded in its place.
0
 
grexxAuthor Commented:
It's a nice option, but it's especially meant for cases where I cannot control the html. So it has to be set on the server side.
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
wesly_chenCommented:
Hi,

    You might want to check the following URL:
http://www.plinko.net/404/howto.asp?article=11

    Basically, create a file called .htaccess in the root directory of the server (the one you refer to as '/') and
have the following line in .htaccess:
-------
ErrorDocument 404 /errors/custom404.html
---------

   Then edit your own custom404.html page.

Regards,

Wesly
0
 
grexxAuthor Commented:
Well, that's for *pages*. I need the same thing but then for *images*. In a page you refer to an image, but that specific image doesn't have to be available. In that case, I want to be able to display a standard error-image.
0
 
wesly_chenCommented:
By the way, error code 404 means the page in the URL is not found. This URL can be an HTML, CGI, or image.

Wesly
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.