How do I create customized error messages for my web page?
Note: This information is applicable primarily to Unix systems running the Apache World Wide Web server, which runs on Mypage and Webserve at Indiana University.
Note: At Indiana University South Bend, the Mypage service is different from the Mypage service mentioned in this document. For more information, see IUSB's Web Publishing: Mypage.
The easiest way to customize the error messages for your site is to
use .htaccess files. With .htaccess files,
you can make your web server substitute pages of your choice for the
generic error messages it normally displays. You may designate different
files for each error message, and with multiple .htaccess files,
you may also create a set of messages for each part of your site.
Follow these instructions to customize your error messages:
- Create web pages for each of your customized error messages. It
doesn't really matter where you put them, but make sure they are
accessible to a web browser.
- Open the
.htaccessfile in a text editor like Emacs, vi, or Pico. You must pay more attention to where you place this file. The server will consult the.htaccessfile every time it tries to access a page from the directory it's in, as well as any subdirectories. If you put another.htaccessfile in a subdirectory, it will override.htaccessfiles in parent directories.
- The syntax for the
.htaccessfile is as follows: ErrorDocument ErrorCode Address ReplaceErrorCodewith the error number of the standard error message you want to replace (e.g.,401,403,404,500) andAddresswith the URL of the file you want as the replacement message, for example: ErrorDocument 403 http://mypage.iu.edu/~dvader/errors/forbidden.html ErrorDocument 404 http://mypage.iu.edu/~dvader/errors/unknown.html HTML error codes have the following meanings:
401Unauthorized. This indicates a password error, for example. 403Forbidden. The file exists, but isn't world readable. 404Unknown. The file doesn't exist at the location specified. 500Internal server error.
If you already have an.htaccessfile (to password-protect a directory, for example), just add theErrorDocumentlines to the end of it.
- Once you have finished, exit your editor and set the protections
of the
.htaccessfile with the following command: chmod 644 .htaccess
At Indiana University, for personal or departmental Linux or Unix systems support, see At IU, how do I get support for Linux or Unix?
Last modified on May 13, 2009.







