Computing & Communications Center
Helpdesk

Customizing a 404

Many people know about the .htaccess script that can be put in their public_html directory, but few know of it's full potential. You can use the .htaccess file to restrict directory access but with a few modifications you can tell the web server to display custom error pages.

The .htaccess should reside in your public_html directory for your changes to come about throughout your directory structure. This means that any subdirectories that you have will also use the directives that you placed in your root .htaccess file.

Creating custom error pages

Sometimes when the web server cannot find a page or if it cannot display the page due to the limited permissions that you have set on it, then it sends an error message to the user. For example, "404: File Not Found", is one of the most notorious errors that the web server sends out. Instead of displaying this cryptic and sometimes useless error message to the user, many people would rather prefer a custom page that includes a link so that they can return to the main page.

The most common errors are:

To tell the web server to point to a custom error page, you need to first create a page that you would like to display instead of the error message. Then edit your root .htaccess file (should be placed in your public_html directory) to include line similar to the following (depending on what error messages you want to override):

ErrorDocument 404 /~yourusername/error404.html
ErrorDocument 403 /~yourusername/error403.html

OR

ErrorDocument 404 http://some_server.com/some_directory/error404.html
ErrorDocument 403 http://some_server.com/some_directory/error403.html

where error404.html and error403.html are the redirects for the two error messages mentioned above. Now every time a user tries to access a file in your public_html that does not exist, the error404.html file will be displayed instead. More information can be found on the Custom error responses page from Apache.org.

Maintained by itweb.
Last modified: Mar 11, 2005, 15:29 EST
[WPI] [Home] [Back]