Home arrow Apache arrow Page 2 - Implementing Sensible 404 Pages With Apache
APACHE

Implementing Sensible 404 Pages With Apache


'HTTP 404 Not Found' reads the title. It's not pretty. As web surfers, we have all collided with 404 error pages, and some endeavour to correct the error be checking the URL for stupid mistakes that often happen. In this article Steve talks about handling 404 errors with Apache, and also suggests ways to keep visitors on your site by making the content of your 404 page informative and useful.

Author Info:
By: Steve Adcock
Rating: 3 stars3 stars3 stars3 stars3 stars / 10
May 01, 2002
TABLE OF CONTENTS:
  1. · Implementing Sensible 404 Pages With Apache
  2. · Custom error documents
  3. · Designing the error document
  4. · Conclusion

print this article
SEARCH DEVARTICLES

Implementing Sensible 404 Pages With Apache - Custom error documents
(Page 2 of 4 )

If your hosting provider runs off of Apache web servers, then all you need is an .htaccess file within the root directory of your web site. Windows based web-hosting companies, however, will often use IIS, or Internet Information Server, where .htaccess files are not supported. Many hosts will offer a control panel, allowing the Webmaster to easily control their web site, modify settings, implement features any many other tasks. If you are unsure about whether or not your host runs off of Apache or IIS, check your control panel, if you have one, for a custom error document option. If your control panel does not contain the ability to setup error pages, or your host does not support control panels, consult with your host's technical support department and inquire about how to set one up. Since custom error document support through Apache is universal, the following will detail how to perform this action.

Setting up error documents with Apache
We will be working with a .htaccess file, which is a file that runs in the background and contains particular options and settings for your web site, one being custom error document codes and locations.

[Note] Some web servers will not display files beginning with a period (.), or dot. Because of this, you will have to search for the document or manually type the document name, in this case .htaccess, into the location bar within your FTP program. [End Note]

Firstly, fire up your FTP program and login to your account through your host. Next, search for a .htaccess file. If you cannot find a .htaccess file on your web site, do not fret. .htaccess files are a snap to create, and we will do just that below.

Creation of .htaccess files can be done with a normal text editor, such as Notepad. You may also use other editors like Editplus, Homesite, etc. To create a .htaccess file with the 404 error document supported, all we need to do is type one simple line of code at the top of the page:

ErrorDocument 404 http://www.yourdomainname.com/custom404page.html

The above line of code contains three different parts. The first part, ErrorDocument, states that you are defining a custom page for one particular error code. The second part, 404, is the actual error code. The third is the location of the custom 404 page. All you need to do is change the location of your error document to your own file on your web server, and you are set. Be sure that the error document (i.e.: custom404page.html) is available on your web server. Save the file as '.htaccess', without the single quotes, of course, and transfer the file over to your web server, usually in your root directory.

Pop quiz. What do you suppose the line would read if you'd like to specify a 500 Internal Server Error page? Yes, that's right:

ErrorDocument 500 http://www.yourdomainname.com/custom500page.html


blog comments powered by Disqus
APACHE ARTICLES

- Programmatically Manipulating Microsoft Exce...
- Installing PHP under Windows
- Compressing Web Content with mod_gzip and mo...
- Compressing Web Output Using mod_deflate and...
- Setting Up Apache 2.0.45 to Parse PHP Pages
- Custom Error 404 Documents with PHP
- Using Apache and PHP on Mac OS X
- ASP: Active Sessions, Active Logins and Tota...
- Working With Oracle on Windows: Part 1
- The Quick-n-Dirty Guide to Setting Up Apache...
- Installing Apache With SSL: The Complete Gui...
- 7 Powerful .htaccess Customization Tips
- Trap And Get Notified: A Practical Solution ...
- One Way To Use Server Side Includes
- Using ForceType For Nicer Page URLs

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 

Developer Shed Affiliates

 




© 2003-2017 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials