Contact Jan Thomas Consulting

February 11, 2009

Capture 404 Errors Gracefully

Filed under: Articles and Reviews, Programming Techniques — AdminJan @ 1:38 pm

Broken Links, Miss-spelled addresses, Unauthorized access, and Server Errors. Turn these errors into opportunities. Capture and keep visitors on your website after an error has occurred by customizing the error reporting page. Provide links, a search box, a back button and a fresh opportunity to explore your site.

Here’s the error page for this site: www.janbthomas.com/oops

1. Create a custom error page in HTML. Add links, a google search box and an identifying logo. Google has some web master tools to help.
I created a page called 404.html

2. Use FTP to copy 404.html to the server. The file 404.html will be displayed whenever the HTTP error code indicates the file is not found.

3. Identify this file to the web server by adding a reference line in the .htaccess file. (This may vary depending on your web hosting company.)

Here’s the line to add:
ErrorDocument 404 http://www.your_domain.com/404.html

4. Upload these changes to the server.

Here are some of the more common HTTP error codes:
Client Errors
400 Bad syntax
403 Forbidden
404 Not Found – Most common

Server Error
500 Internal Error

5. As an alternative, capture all errors with the same file by adding a few lines into the .htaccess file.

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) /errors.html

In this example, the HTML error page is called errors.html

No Comments

No comments yet.

RSS feed for comments on this post. TrackBack URL

Sorry, the comment form is closed at this time.

Powered by WordPress