Link to home
Start Free TrialLog in
Avatar of grexx
grexx

asked on

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?
Avatar of Diablo84
Diablo84

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.
Avatar of grexx

ASKER

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.
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
Avatar of grexx

ASKER

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.
ASKER CERTIFIED SOLUTION
Avatar of wesly_chen
wesly_chen
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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