Search

  Add URL | Add Premium URL

Making Custom 404 Error Pages  

by: Shawn Stoner

Have you ever clicked a link and seen the dreaded white page with:

The page cannot be found
The page you are looking for might have been removed, had its name changed, or is temporarily unavailable.

Please try the following:
* If you typed the page address in the Address bar, make sure that it is spelled correctly.
* Open the sites home page, and then look for links to the information you want. 
* Click the Back button to try another link. 
* Click Search to look for information on the Internet. 

HTTP 404 - File not found
Internet Explorer 

This message can be cryptic for visitors to your site - it does not give a lot of information on how to correct the problem. Some user may even leave your site after receiving a 404 error. If you have seen 404 errors in your server logs or just want to make your visitors feel at home on your site, then this is going to be useful information for you.!

This is a list of common page errors and their meanings:

400 - Indicates the syntax of the request was bad.

401 - Authorization is required. The name/password provided with the request (if any) does not match an authorized person.

403 - Forbidden. The request was understood but the server is not allowed to serve the resource that was requested.

404 - Not found. The resource named is not present on the server.

406 - Not acceptable. The client's request included some "accept" qualifications, which were not met.

407 - Proxy authentication required.

408 - Request timeout. The server was waiting for the completion of the request and it took too long.

409 - Conflict. Current server state prohibits fulfilling the request.

410 - Gone. The requested resource is not available now nor is it ever likely to be available on the future.

411 - Length required. The request needs to have a length value supplied by the client.

412 - A condition specified in a request header was false.

413 - Too large. The request entity was too large for the server.

414 - Request URI too long. Longer than the server would accept.

500 - Internal server error.

503 - Service not available. The server can't fulfill the request at this time. Try again later.


The most common that you have probably seen are 500,404, and 403 errors.

Creating the Custom 404 page.

Depending on the type of web server your site is hosted on, you can set up custom error pages several different ways. This Tutorial will focus on error pages for Apache servers.

First create a custom 404 page(I recommend using the same layout as your site) and call it custom404.html and upload it to your hosting server. You can place this file in a folder if you wish. You may want to make all the links absolute in your file rather than virtual. 

For example:

Change /images/yourimage.gif to http://www.yourdomain.com/images/yourimage.gif. This will also need to be done for any links to pages on the page. This will keep the images and links from being broken if the page they are trying access is in a sub-directory of the server.

I recommend making the page look like the rest of your site. You can add a custom message telling the visitor what to do or how to find the page they are looking for.

For example:

"The page you are trying to access no longer exists or has been changed. If you typed the URL please check the spelling. If you clicked a link, please notify our staff. Please select from the menu below to go to a new page."

Next, you can edit or add a file called .htaccess in the root directory of your hosting account.

You can add an entry to it like the following:

ErrorDocument 404 /errors/custom404.html

This means that if someone tries to access a page that does not exist, they will see your custom HTML page called custom404.html. 

You can also use this in your .htaccess document:

ErrorDocument 404 "Sorry, this page doesn't exist.

Make sure you begin the text with a quote ("). This will display the text you indicate.
Windows users have reported problems creating .htaccess files. Create a file named 'htaccess.txt', FTP it to your web host, and then rename it to .htaccess.


Other Methods

You can use a CGI script for error pages also. You can search Google or Yahoo and probably find a lot of pages on CGI scripts for custom error pages. 

This tutorial was written by: Shawn Stoner,  The Web Smart  - Tucson Web design and development

 

Back to Articles   Directory

Copyright 2002-2003 Web World Index