Creating Custom Error Messages
You can create your own custom error messages to substitute the default error messages generated by the server, such as the common "404 Not Found." Use custom error messages when you want to display friendlier error messages to your visitors.
Custom error messages can be used:
- To substitute error messages such as "404 Not Found" and "403 Not Authorized".
- To create error messages that fit the design of your site.
- To create error messages that provide more information than usual.
The following instructions show how to create a custom error message to replace the default "404 Not Found" message.
Create a Web page which contains your custom error message. The following steps refer to this Web page as "notfound.html".
Upload "notfound.html" to your public_html directory and verify that it can be opened with a Web browser.
At the prompt, enter the following command to change directories to your Web directory:
At the prompt, enter the following command to create a .htaccess file in the current working directory:
To create a custom "404 Not Found" message, add the following line to this file:
ErrorDocument 404 /uwnetid/notfound.html
Replace uwnetid with your UW NetID and, if need be, notfound.html with the filename containing your custom error message.
Tip: You can add additional lines with other error codes (eg 404, 403, 500) you wish to replace. Note that you may have each error code listed only once per .htaccess file; refer to the examples below.
Save and close the file using Pico. (Click for instructions on how to use pico).
Note: Microsoft Internet Explorer does not display custom error messages by default; it displays its own built-in messages. You can change this by unchecking the "Show Friendly HTTP Messages" options found under "Tools" > "Internet Options" > "Advanced". Of course, it is doubtful that your visitors will have this option unchecked, and thus they might not see your custom error messages.
Here are some examples:
Use files in a subdirectory for your error messages (e.g. "public_html/errordocs/" subdirectory):
ErrorDocument 404 /userid/errordocs/404.html
ErrorDocument 403 /userid/errordocs/403.html
Use an internal location in your Web site:
ErrorDocument 404 /userid/errordocs/
ErrorDocument 403 /userid/errordocs/
Use an external location outside your Web site:
ErrorDocument 404 http://www.some-site.washington.edu
ErrorDocument 403 http://www.another-site.washington.edu
Note: 404 (Not Found), 403 (Not Authorized), and 500 (Server Error) are "response codes" defined in the HTTP specification.
To learn more about custom error messages and the ErrorDocument directive refer to:
- ErrorDocument directive (offical Apache documentation)
- Error Documents (for www.washington.edu developers)