Improve Site Performance Increase Site Traffic Monitor Site Uptime Webmaster Resources NetMechanic Home Looking For Help? Partner Programs Privacy Policy Contact Us Press Room
NetMechanic Home LOGIN | HELP | ABOUT US | PRODUCTS | SITE MAP
NetMechanic Menu
Over 52 Million Web Pages Tested!     
 

Search for:


Your Email:

I would like to receive my newsletter in:
HTML format
Text format



Volume 8 (2005)
   September
   June
   April
   March
   January

Volume 7 (2004)
   November
   September
   July
   June
   May
   April
   March
   February (Part 2)
   February
   January (Part 2)
   January

Volume 6 (2003)
   December
   November (Part 2)
   November
   September
   August (Part 2)
   August
   July (Part 2)
   July
   June (Part 2)
   June
   May (Part 2)
   May
   April (Part 2)
   April
   March (Part 2)
   March
   February (Part 2)
   February
   January (Part 2)
   January

Volume 5 (2002)
   December (Part 2)
   December
   November (Part 2)
   November
   October (Part 2)
   October
   September (Part 2)
   September
   August (Part 2)
   August
   July (Part 2)
   July
   June (Part2)
   June
   May (Part 2)
   May
   April (Part 2)
   April
   March (Part 2)
   March
   February (Part 2)
   February
   January (Part 2)
   January

Volume 4 (2001)
   December (Part 2)
   December
   November (Part 2)
   November
   October (Part 2)
   October
   September (Part 2)
   September
   August (Part 2)
   August
   July (Part 2)
   July
   June (Part 2)
   June
   May (Part 2)
   May
   April (Part 2)
   April
   March (Part 2)
   March
   February (Part 2)
   February
   January (Part 2)
   January

Volume 3 (2000)
   December (Part 2)
   December
   November (Part 2)
   November
   October (Part 2)
   October
   September (Part 2)
   September
   August (Part 2)
   August
   July (Part 2)
   July
   June
   May
   April
   March
   February
   January

Volume 2 (1999)
   December
   November
   October
   September
   July
   June
   May
   April
   March
   February
   January

Volume 1 (1998)
   December
   November
   October
   September

 
Updated October 22, 2001

Server Tip:
Create a Custom Error Document

by Tom Dahm,
Chief Operations Officer,
NetMechanic, Inc.

  
June 1999
Vol. 2, No. 6
 • Server Tip
 • HTML Tip
 • Business Tip
  

Do you rent space on someone else's Web server? Even if you do, you can still customize much of the server's behavior. It's easier than you might think. This tip will show you how to change your Web server to use a custom error page. You can serve a page that has your Website's look and feel, instead of the generic "404 - File Not Found" page.

Web servers are highly configurable applications whose behavior is controlled by a series of commands called server directives. Apache, the world's most popular Web server, supports about 200 of these directives.

Server directives are stored in a series of server configuration files. These files are controlled by your server administrator, and only he or she can change them. That's a good idea, since most directives are global; changing them changes the way the server works for everyone.

But some server directives control things that are local to each virtual host. You need a way to set these directives so that they apply only to your Web site and not to all sites running on the server.

Fortunately most Web servers let you do this through something called an ".htaccess" file (Notice the dot at the beginning of the file name - it's required). The .htaccess file is a text file that's placed in the domain root for your site; in other words, you put it in the same directory as your site's home page. You may have to create a fresh .htaccess file if there's not already one there.

These .htaccess files are most often used to put files and directories under password protection, but they can be used for a lot of other things too, like server-side redirects. Apache allows over 40 of its 200 directives to be placed in an .htaccess file. To set up a custom error page, we only need to use one of these directives, called ErrorDocument. To use this directive, add this line to your .htaccess file:

ErrorDocument 404 /error_page.html

This line has of three parts:

  1. ErrorDocument is the server directive itself.
  2. A server status code to which this directive applies.
  3. The HTML file that should be served when the status code occurs.

In this example the status code is 404, which is the standard "file not found" error code you get when clicking on a broken link.

You can use different ErrorDocument directives to apply to different errors by adding extra ErrorDocument lines to the .htaccess file. So you might add a second line that looks like this:

ErrorDocument 500  /script_error.html

This would make the server use a different page when a CGI script has an internal error. The table below shows some common server status codes and when they might occur.

Status Code Label Explanation
401 Authorization Required Directory is protected by a password
403 Forbidden All visitors are barred from looking at this file or directory
404 File Not Found Missing file
500 Internal Server Error CGI script error

In our examples above, the location of the custom error page is given by a virtual path. That is to say, it starts with a slash followed by the file name, so the file should be placed in the domain root. You could also use an absolute URL to give the file's location. The file can even be a CGI script that executes when the condition occurs.

As with most things on the Web, there's a downside to using an .htaccess file. Since the server has to check for these files and process them, they introduce a slight degradation in server performance. Overall, the benefits from improving the look of your site probably outweigh the penalty.

Try using an .htaccess file on your site. After you're comfortable with simple commands like ErrorDocument, you can experiment with other directives. A full list of directives supported by Apache is available at the Apache Server Project site.



Rate This Tip:
Not Useful Useful Very Useful   
 
NetMechanic Tools
HTML Toolbox
Browser Photo
Server Check
Search Engine Starter
Search Engine Tools
GIFBot
Newsletter
HTML Tutorial and Tips
Search Engine Tutorial
Accessibility Information
Browser Problem Tutorial

Company Info
Products
About Us
Contact
Advertise
Link To Us
Jobs
Privacy Policy
Partner Programs
Press Room
RSS Feed
Support
 



Powered by Overture!

 
     
 
   
 
     


Keynote Home
Copyright © 1996-2007,
Keynote NetMechanic
All rights reserved.