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.
The easiest way to customize the error messages for your site is to
.htaccess files. With
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
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 Replace
ErrorCodewith the error number of the standard error message you want to replace (e.g.,
Addresswith 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:
Unauthorized. This indicates a password error, for example.
Forbidden. The file exists, but isn't world readable.
Unknown. The file doesn't exist at the location specified.
Internal server error.
If you already have an
.htaccessfile (to password-protect a directory, for example), just add the
ErrorDocumentlines to the end of it.
- Once you have finished, exit your editor and set the protections
.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 June 26, 2012.