Navigation Map

Help Desk Home

Homebuilder

Network Operations Center

Uploading
References
Trouble Shooting
Special Characters

Counters
Forms
Password Control
RealAudio
Imagemaps
Mime Types
Web Stats

CGI Basics
Custom CGI
File Permissions
SSI's
Java!
MySQL
PHP(3)
Custom Errors
Virtual Domain FAQ
Secure Server Info

IO Web Helpdesk - Custom Error Messages


To create custom error messages for your website, just create a file named ".htaccess" in any subdirectory from which you serve web pages. These custom error messages will apply to that directory and all subdirectories beneath it.

Here is an example .htaccess file:

ErrorDocument 403 /errors/restricted.html
ErrorDocument 404 "Sorry, that file was not found."
ErrorDocument 500 http://www.dezines.com/errors/server_error.html

In this example:

  1. If the user requests a document to which access is not allowed (a 403 error), they will be shown the document "/errors/restricted.html"
    This is just as if they requested http://www.servername.com/errors/restricted.html, except the URL they see will be the one they entered, for example, "http://www.servername.com/.htaccess"

    For this to work, the filename given MUST be absolute, for example,
    /errors/restricted.html, and not "errors/restricted.html", as this is actually the trailing part of the URL to be effectively shown. If the "/" is omitted, instead the error would be shown as text, as in the next example.
  2. If the user requests a document that does not exist (a 404 error), they will be simply shown the text "Sorry, that file was not found." Note the lack of the trailing quotation mark; this is intentional, as it otherwise will be displayed.
  3. If the user requests a document that causes a server error (a 500 error), such as a malfunctioning CGI program, they will be redirected to the URL "http://www.dezines.com/errors/server_error.html". This is different from the first example, in that here the browser is actually told to fetch this new document at the given URL, instead of the contents of that URL simply being sent along to the browser with no perceived redirection as in the first example.

Hints:

  • Any error can be redirected to a CGI script instead of a .html file, which could provide detailed information about the error, and also log any pertinent information in a MUCH more detailed manner than Apache does by default.
  • However, DO NOT redirect 500 errors to a .CGI script, because if .CGI happens to not be functioning, an endless loop will be created!
  • Remember that any error number can be given any of the types of redirection responses as shown above, but generally the most useful is the first form where the .html file or .cgi program is simply shown in place of the default error message.
  • Be careful not to restrict access to the /errors directory (or whatever directory you place the error messages in), so that weird things don't happen.


Last revised November 19, 1999