Solved

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

Posted on 2004-10-29
221 Views
Last Modified: 2010-03-04
Is there a way to let apache serve a custom error image when an image is requested that does not exist on the server?
0
Question by:grexx
    6 Comments
     
    LVL 27

    Expert Comment

    by: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.
    0
     
    LVL 1

    Author Comment

    by:grexx
    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
     
    LVL 38

    Expert Comment

    by:wesly_chen
    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
     
    LVL 1

    Author Comment

    by:grexx
    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
     
    LVL 38

    Accepted Solution

    by:
    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
     
    LVL 38

    Expert Comment

    by:wesly_chen
    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

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone. Privacy Policy Terms of Use

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    As Wikipedia explains 'robots.txt' as -- the robot exclusion standard, also known as the Robots Exclusion Protocol or robots.txt protocol, is a convention to prevent cooperating web spiders and other web robots from accessing all or part of a websit…
    If you've heard about htaccess and it sounds like it does what you want, but you're not sure how it works... well, you're in the right place. Read on. Some Basics #1. It's a file and its filename is .htaccess (yes, with a dot in the front). #…
    With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…

    877 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    12 Experts available now in Live!

    Get 1:1 Help Now