Affordable Web Hosting with Excellent Customer Support internet connection free month hosting

Custom 404 (File Not Found) and Other Error Pages

If you've spent enough time surfing the web you've probably run across quite a few HTTP error pages. Of these, the 404 "File Not Found" error is the most common, but you might have also seen 500 "Internal Server Error" and 401 "Unauthorized" errors as well. In most cases these server error pages are very basic, even cryptic, providing information that is useless to most web surfers.

For example, here is the standard error page that visitors to your site see if they click on a broken link or request a document that does not exist:

Screenshot of 404 File Not Found error page

While not as cryptic as the standard 500 "Internal Server Error" page, the page is still very basic. By creating and using custom error pages, you replace this basic page with one that matches the look and feel of your site. Plus you can provide a better experience for your visitors by:

  • including a better description of why they've arrived at an error page
  • adding some functionality on the error page to assist them achieve their goal

Here's an example of the custom 404 "File Not Found" error page used on the Internet Connection site:

Screenshot of custom 404 File Not Found error page

As you can see, it maintains the look of the rest of site, offers a description of the error and why it may have occured, and offers the visitor to search for the page they were looking for.

Creating Custom Error Pages

Before opening your favorite HTML editor to bang out your custom error pages, you should first decide which errors you want to make pages for. As mentioned above, the three most common are the 404 "File Not Found", 500 "Internal Server Error", and 401 "Unauthorized" errors. However, if your site doesn't use any CGI or does not have a password-protected area, your visitors will not encounter the 500 or 401 errors. Fortunately your log files contain information on what errors your visitors do receive. Linux hosting customers can access the Log Analysis section of their netConsole for a table of "Hits by Response Code". Customers using an Internet Connection Windows 2000 Advanced Server will have to download their log file and process it manually to get this information.

Once you've decided on which errors to create custom pages for, go ahead and create them. Here are some suggestions for when you create your custom error pages:

  • Make paths to images and other externally-referenced files (.js, .css) absolute. E.g. images should be accessed like so:

    <img src="http://www.your-domain-name/images/image.gif" />

    This is to ensure that your pages display correctly regardless of where they are encountered.
  • If you create a custom 404 "File Not Found" page, include the ability for the visitor to search for the document they were seeking. The Search Package in the Linux netConsole is perfect for this. Alternatively, you can link to or display a site map on this page to allow the visitor to browse your site.
  • If you create a custom 401 "Unathorized" page, and your password-protected area is open to general public "subscription", include either a link to a page where the visitor can sign up, or have the sign up form directly on the custom error page.
  • You probably won't want your custom error pages to be spidered and indexed by search engine. To ensure this, place this meta tag within the <head> </head> tags at the top of your page:

    <meta name="robots" content="noindex, nofollow">

  • Be sure your page is over 1,024 bytes in size. Some browsers will not display error pages that are smaller than this.

Specifying Custom Error Pages (Linux hosting customers)

After creating the custom pages for your site, you must configure Apache, the web server on Internet Connection's Linux servers, to use these custom pages instead of the standard error pages. This is done with an Apache configuration file, called .htaccess. In most cases this file will already exist in your webshare directory and you can either edit it on the server with vi, or download it for offline editing*. Here is an sample .htaccess file which specifies custom error pages for the 401 "Unauthorized" and 404 "File Not Found" errors:

ErrorDocument   401     http://internetconnection.net/signup.shtml
ErrorDocument   404     http://internetconnection.net/notfound.shtml

As you can see, the sytax for specifying these is pretty simple. The word "ErrorDocument" followed by white-space followed by the numerical error code followed by another white-space followed by the URL to the custom error page. The word "ErrorDocument" is not case-sensitive and the URL to your custom page can be absolute, as the ones above are, or it can be relative like so:

ErrorDocument   401     /signup.shtml
ErrorDocument   404     /error_pages/notfound.shtml

If you do not already have an .htaccess file in your webshare directory you can easily create one. The .htaccess file is a text file that can be created in any simple text editor. Please note that if your personal computer or workstation uses a Windows operating system, you will not be permitted to create a file named .htaccess. What you must do is name the file something like htaccess.txt, upload it*, then rename it to .htaccess on the server.

*Note: If you've edited your .htaccess file offline or created a new file you will have to transfer the file back to the server via FTP, SFTP, SCP, etc. To ensure that your modified or new file work correctly it must be uploaded in ASCII/text mode and the permissions need to be set to 644.

Specifying Custom Error Pages (Windows hosting customers)

Unfortunately Internet Information Services (IIS), the web server software used on Internet Connection's Windows 2000 servers, does not allow user-level manipulation of it's configuration. If your site is hosted on one of our Windows 2000 servers, you must contact the Support Desk to request that custom error pages be set up for your hosting account. When you do this please include the full path to your custom error page(s) and the numeric error code(s) that corresponds to each one.

For example, to request that your file "notfound.asp" be set up as the custom 404 "File Not Found" error page, send this infomation:

Hello,

Please set this file:

http://my-domain-name/notfound.asp

as the 404 File Not Found error page for my site.

Compatibility Notes

If your site is hosted on one of Internet Connection's Linux server and you're using the 404 Notification Package available in the netConsole, you can potentially break the functionality of that script by specifying a custom 404 "File Not Found" error page. To ensure the functionality of that script remains intact, please see the "Things to Remember" section of the 404 Notification Package documentation.

Related Items