UB Information Technology


Custom Errors

It is very common for Web users to access a page that doesn't exist in your site. This can be due to a mistyped address, a page that moved, solar flares, or a broken link.

The normal error page for UBWings simply tells the user that the file wasn't found but doesn't provide any more help than a few navigational links to hopefully point them in the right direction. However, you have the ability to create your own error page for your site, which can greatly assist your users.


Fig. 1 - A bad error page


Fig. 2 - A better error page

Step 1: Create the error page

A good error page should provide a list of links to help people navigate your site. It should also contain an email address for users to send mail to if they encounter problems.

You may want to create a separate error page for each of the most common errors:

  • File not found (404)
  • File not readable (403)
  • Bad Username/Password (401)
  • Bad CGI Program (500)

Step 2: Upload the error page(s)

Upload the error pages into your site. You will probably want to name them something meaningful such as 'error404.html' and 'error500.html'.

Step 3: Create the .htaccess file

Create a file called .htaccess in your directory. The file should normally have only one line per error type:

ErrorDocument 404 /PATH_TO_YOUR_DIRECTORY/error404.html
ErrorDocument 500 /PATH_TO_YOUR_DIRECTORY/error500.html

Examples:
If your URL is http://wings.buffalo.edu/academic/department/abc, then your .htaccess file would look like this:
ErrorDocument 404 /academic/department/abc/error.html

If your URL is a virtual host like http://abc-department.buffalo.edu/, then your .htaccess file would look like this:
ErrorDocument 404 /error404.html

Troubleshooting

If things don't work correctly, first check your permissions. You may need to make the .htaccess and error files readable:
chmod 755 .htaccess
chmod 755 error404.html

You may also want to add a blank line at the end of the .htaccess file.