Web Development Support
    General Info   Cool Tools
    Getting Started   Troubleshooting
    Design & Promotion   Feedback
 

Search this site:


view site map

Custom error pages with Apache

  1. What are custom error pages?
  2. How to create a custom error page

What are custom error pages?

Normally, when a person surfs to a broken link in your site, or enters a URL incorrectly, they will see an error message such as "An Error Has Occurred! URL not found." With custom error pages, you create a more attractive error page that has the look and feel of the rest of your site. This is a rather difficult and advanced procedure which requires copying and editing files in UNIX. We recommend using custom error pages as a third or fourth generation modification to your site.


How to create a custom error page

You should start with the standard Apache error 404 file. It contains a couple of Server Side Includes that give the URL of the requested page, and the URL of the referring page that contained the bad link.

1) Log in to your UNIX account. You will need to enter the following commands at the UNIX command line in order to copy the Apache error file into your public_html directory.

cd public_html
cp /www/apache/htdocs/errors/e_404.html e_404.html

If you are unable to find the e_404.html file, you may obtain a copy of the file from this site.

2) Use ftp (or Home Directory) to download the file to your local machine. Viewing the file in your Web browser and saving it will remove the SSIs, so only ftp or Home Directory will work.

3) After you have downloaded the file, use your Web editor (Dreamweaver, etc.) to edit this file to reflect the look and feel of your site. Keep the SSIs unchanged. An SSI is a specially formatted HTML comment. Once you have finished, you should upload the file back to your public_html directory.

4) Using a plain text editor, create a file in your web site's directory named:

.htaccess

Yes, that is a dot at the beginning of the file. UNIX configuration files often begin with a dot. This type of file is referred to as a "dot file" or in particular this case "dot h t access". (as another example .pinerc is called "dot pine r c")

Apache configuration commands are called "directives". You can create customized sets of commands, although you must place them in a specially named file in your public_html directory. The Redirects discussed below also use Apache directives. You can have many directives in a single .htaccess file.

5) The contents of your .htaccess file depend on what type of site you have.

  • If you have a site with a tilde (~) in the URL, such as http://www.people.virginia.edu/~mst3k, you should put the following contents in your .htaccess file:
Options Includes FollowSymLinks ExecCGI
ErrorDocument 404 /~mst3k/e_404.html
  • If you are working on a departmental page, such as http://www.virginia.edu/somedepartment, you should put the following contents in your .htaccess file:
Options Includes FollowSymLinks ExecCGI
ErrorDocument 404 /somedepartment/e_404.html
  • If you are working on a virtual host site, such as http://someplace.virginia.edu, you should put the following contents in your .htaccess file:
Options Includes FollowSymLinks ExecCGI
ErrorDocument 404 /e_404.html

 

6) Save your file.

Web Development Support | General Info | Getting Started | Design & Promotion
Cool Tools | Troubleshooting | Feedback

If you need further assistance with Web applications or questions, send e-mail to web-consult@virginia.edu or call the ITC Help Desk at 924-3731.

© 2008 by the Rector and Visitors of the University of Virginia.

The information contained on the University of Virginia’s Department of Information Technology and Communication (ITC) website is provided as a public service with the understanding that ITC makes no representations or warranties, either expressed or implied, concerning the accuracy, completeness, reliability or suitability of the information, including warrantees of title, non-infringement of copyright or patent rights of others. These pages are expected to represent the University of Virginia community and the State of Virginia in a professional manner in accordance with the University of Virginia’s Computing Policies.