Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


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

Posted on 2004-10-29
Medium Priority
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?
Question by:grexx
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
LVL 27

Expert Comment

ID: 12448101
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.

Author Comment

ID: 12448929
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.
LVL 38

Expert Comment

ID: 12454482

    You might want to check the following URL:

    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.


Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!


Author Comment

ID: 12454725
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.
LVL 38

Accepted Solution

wesly_chen earned 500 total points
ID: 12455038
   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).

LVL 38

Expert Comment

ID: 12455046
By the way, error code 404 means the page in the URL is not found. This URL can be an HTML, CGI, or image.


Featured Post

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Over the last year I have answered a couple of basic URL rewriting questions several times so I thought I might as well have a stab at: explaining the basics, providing a few useful links and consolidating some of the most common queries into a sing…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Suggested Courses
Course of the Month11 days, 17 hours left to enroll

636 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