Home arrow Apache arrow Page 2 - Handling 404 Error's With Apache

Handling 404 Error's With Apache

The web is all about usability, consistency and speed... well, that's what we'd like to think anyway. In this article John shows us how to stop those dreaded 404 errors from plaguing our Apach-based web sites. With a bit of PHP and a htaccess file or two, your site will be free of 404's forever!

Author Info:
By: John Ferme
Rating: 4 stars4 stars4 stars4 stars4 stars / 9
February 20, 2002
  1. · Handling 404 Error's With Apache
  2. · Apache and hierarchies
  3. · Implementing a 404 trap
  4. · Conclusion

print this article

Handling 404 Error's With Apache - Apache and hierarchies
(Page 2 of 4 )

Apache is a very configurable web server, and it depicts a web site as a hierarchically structured set of files and directories. These directories are organized with parent-child relationships, like this:

A typical file system setup

Apache also supports configuration files knows as htaccess files. These files can be used to set various file/directory permissions, redirection attributes, and block users coming from a specific IP address, etc. Htaccess files are created with the filename ".htaccess" (notice the dot at the beginning of the filename) and can reside in any directory that an Apache server can process.

Because of the way Apache works, if I had an htaccess file saved in a directory called home and this directory also contained several sub-directories, then each sub-directory would be influenced by the htaccess file in the home directory as well.

Think of a situation in which you might want to password protect several directories on your web site; your web site may be structured with one main root directory and 23 sub-directories. By simply placing a specially designed htaccess file in the root directory, all 23 sub-directories are automatically protected as well. This is a great time-saver, because usually if you're modifying the attributes of one directory, then there's a good chance that you'd like the attributes of all of its sub-directories affected by affected as well.

Hopefully you now understand the benefits of Apache thinking in terms of a hierarchy. We can use this hierarchical structure to our benefit by creating a htaccess file that can trap 404 errors and redirect the user to the appropriate page or perform some specific action depending on the URL that the visitor typed in. Let's do that now.
blog comments powered by Disqus

- 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 

Developer Shed Affiliates


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