Apache gives you the ability to use custom error strings or documents. This can be configured for different types of errors, and you can specify either a file or a script to process the error.
.htaccess file is used
to enable error documents, using the ErrorDocument command. This
command takes two arguments, an error code, and a URL which
should process the error.
As an example, the
.htaccess file used by this
ErrorDocument 401 /webinfo/error/auth_required.html ErrorDocument 403 /webinfo/error/forbidden.cgi ErrorDocument 404 /webinfo/error/not_found.cgi ErrorDocument 500 /webinfo/error/server_error.cgi
Note: If you are working in wwwdev, wwwudev, or the
production directories for www.washington.edu, you need to have
the ErrorDocument entries in a
.htaccess file in
each tree you use. For example, if you use the world and uw
trees, you need to have a
.htaccess file with these
ErrorDocument lines in each tree.
Also, if you do not already have a directory in the world
tree, you must have one made and put a copy of the
.htaccess file there, or the File Not Found error
document will not be used.
The error codes used above are the most common ones. Their definitions are:
If you choose to supply an error CGI
script, the usual CGI variables are available for use, but they
REDIRECT_ string prepended to them. For
example, the usual variable
REMOTE_HOST will instead
REDIRECT_REMOTE_HOST. You're always
guaranteed to have the
REDIRECT_URL (URL which
generated the error) and
(arguments after the
? in the URL) variables.
If the server registered a string explaining the reason for
the error, that string is available as
Here are examples of the error documents defined
.htaccess file above.
Authorization Required - One way of handling an invalid username/password pair is to offer the user the chance to register so they can gain access to the pages which are protected. This is an example of that. Be sure to cancel the dialog box so you can see the error document. You can also view the source to this document.
Access Denied - This script will detect whether you are trying to do a directory listing (as in this case) or trying to access a file which can't be read (or your username/password doesn't have access to). You can view the source to this perl script.
File Not Found - This is a shell script which will tell a user that a file they are looking for isn't there. If the user came via a link and that information has been passed to us, the script will note that, too. You can also view the source to the script.
Server Error - This link points to a CGI which returns an error, triggering the Server Error. You can view the source to this error script.