MikroSight.com

MikroSight.com

| Home | NPA/NPX |

Google
Web
MikroSight

What little I know about Custom Error Pages

NOTE: The servers I use are all Linux/Apache based, some of this information may/may not apply to Microsoft IIS servers.

Document Length

Some browsers, specifically Microsoft Internet Explorer, will display "Friendly HTTP Error Messages" under certain conditions. The main thing we, as page designers, need to know is that the length of the Error page is important in IE's decision as to what to display. 

Depending on the version of IE, how the user's IE options are set, and the particular HTTP Error code, Microsoft may elect to display one of their "Friendly HTTP Error Messages" even if our custom error documents are setup and in place.

This document length issue differs for IE 4 versus IE 5.x+ - I think for IE 4 the length was 512 bytes for all the error codes listed below - a change came with IE 5.x+, and now these values are stored in the registry under

HKEY_LOCAL_MACHINE\Software\Microsoft\Internet Explorer\Main\ ErrorThresholds

Each code is listed here with the Error number and minimum length

The codes that IE does this for are 400, 403, 404, 405, 406, 408, 409, 410, 500, 501, 505

The defaults on my Win98SE machine using IE 6.0.2800.1106 are all 512 bytes except for codes 403, 405, 410 which are set to 256 bytes.

Update as of 12/1/06 - on my XP Home machine, using IE7, the registry values are the same.

So, given these defaults have not been changed by the user, and as long as our error documents are greater than 512 bytes in length, IE will show our page regardless of how the user has the "Show Friendly HTTP Error Messages" set in their IE Advanced Options settings.  This is a problem for IIS servers as well and Microsoft has provided a program to IIS administrators to pad their custom error documents to 513 bytes.

Most of the information about all this came from the Microsoft KnowledgeBase - see this article 174662 for more information and additional links.

Absolute Links versus Relative Links

Another point to remember - All hyperlinks in your error document(s) must be absolute references.

Some HTML editors including Microsoft FrontPage will show links to other pages within the same site using relative URIs.  For example, a link to this page from another page within this site can be shown as a relative location to the current page

/tutorials/customerrors.shtml

OR as a complete URL which is an absolute location on the web

http://www.mikrosight.com/tutorials/customerrors.shtml

On error documents, the 2nd choice is the one to use.  Using FrontPage 2000, I had to manually edit the hyperlinks to show an absolute link - thankfully, I only wrote a single Error Document Page to handle all the errors on my site.

Other Custom Error Page Considerations

There are some generally accepted design principles to use on your error documents - some of these are debatable, some just make sense to me.

  • Don't show all your "normal" navigation links like sidebars, etc
  • DO show a link to your home page
  • DO show a link to your site map page if you have one
  • DO provide a "Search this site" box if you have one, or alternately a link to a Search Page for your site

Setting Up Custom Error Pages in Linux/Apache

Now-a-days, Most Linux/Apache hosts provide some type of Control Panel software for you to use to control various features for your site.  CPanel is one of the more commonly used control panels and it includes an "Error Pages" option on the menu. CPanel describes this option this way

"With this tool you can create custom error pages to display when a user enters a wrong URL, an outdated URL or when the user is not authorized to access a specific directory in your web space."

CPanel allows you to define a separate page for the more commonly encountered errors.

If you don't have a control panel, or you just want more control over the situation, you probably can use the Apache .htaccess file to control the Error Documents. For each error code you want to trap, enter a separate line in .htaccess of the web root.  Here is one of mine

ErrorDocument 404 /notfound.php?en=404

This tells Apache that when an error 404 is encounter to show the page notfound.php

Using CGI, PHP, or SSI for Custom Error Pages

Some people think that a custom error document has to be a HTM file.  When I first customized mine, I started with a simple .HTM file, then I moved to .SHTML so I could get access to some of the SSI variables.  Next came CGI so I could get a copy of the error e-mailed to me at the time it happened. 

You may have noticed from the above example, that I am now using PHP.  The change to PHP was made so I could further customize the error page based on the specific error and I can still e-mail myself a copy of the error when it happens.

To check out our custom error page, here's a bad link to this site.  You should land on our custom error page with a 404 - Page Not Found error indicated.