Apache
  Home arrow Apache arrow Page 4 - Custom Error Pages with Apache
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
VPS Hosting  
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid  
Request Media Kit
Contact Us  
Site Map  
Privacy Policy  
Support  
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
Google.com  
APACHE

Custom Error Pages with Apache
By: Dan Wellman
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 11
    2006-04-03


    Table of Contents:
  • Custom Error Pages with Apache
  • Creating a custom error page
  • Internationalized error pages
  • Maintaining and updating error pages

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article

     
     
    ADVERTISEMENT


    Custom Error Pages with Apache - Maintaining and updating error pages
    ( Page 4 of 4 )

    You are now faced with the same problem that we initially set out to fix: bland and generally unhelpful error response documents.  However, the fact that the server-generated page makes use of included html pages means that you have a centralized method of maintaining and updating these error pages to fit in with your site's design, making them much easier to customize and manage.  If you look at one of the include pages in a text editor, you’ll see a special section there that defines some very basic styles.  This is where you can add your own style rules in order to customize the look of the error page.

    The 404 response is probably going to be the most common error result that is going to be seen by visitors to your site.  Sometimes, this is going to be because they’ve misspelled a URL or clicked on a link to a resource that no longer exists, but very often, it can be the result of site reorganization, or pages being moved from one directory to another within your site's internal structure.  Client redirection is extremely easy to configure; you simply use the Redirect directive, the name of the old directory and the URL of where requests to the old directory are redirected to:

    Redirect /olddir/ http://localhost/newdir/

    This will only be effective when there are no longer any pages in the olddir directory however, as any request for a page within that directory will be redirected to the newdir, so a request for www.mysite.co.uk/2005/quarter1.html where 2005 is set in the place of olddir will automatically be redirected to www.mysite.co.uk/2006/quarter1.html when http://mysite.co.uk/2006/ is set as the newdir.  If just an individual page has been moved, you can simply add a directive specifically for the page that has moved:

    Redirect /olddir/movedpage.html
    http://localhost/newdir/movedpage.html

    You can even use the Redirect directive in conjunction with your customized error pages by making use of the status argument, which comes directly after the directive name.  The status can be an error code or one of several keywords.  If, for example, a page has been removed from your site rather than just moved, you can add the following directive to your conf file to let visitors know:

    Redirect 404 /olddir/deletedpage.html

    This will generate the HTTP_GONE.html.var error response when internationalized error messages have been configured.

    Apache has many other directives that can be used to deal with ever more complex redirection issues, but these are beyond the scope of this article.  You’ve seen how easy it is to configure your own set of custom error response pages, and how to enable customized error responses that can be displayed in a variety of languages depending on the preferences of requesting clients.  Additionally, you’ve learned how to redirect browsers when requesting pages that have moved or been removed so you can try to minimize the number of times your custom error pages need to be displayed.



     
     
    >>> More Apache Articles          >>> More By Dan Wellman
     

       

    APACHE ARTICLES

    - Creating a VAMP (Vista, Apache, MySQL, PHP) ...
    - Putting Apache in Jail
    - Containing Intrusions in Apache
    - Server Limits for Apache Security
    - Setting Permissions in Apache
    - Installing Apache
    - Apache Installation and Configuration
    - Apache Tapestry and Custom Components: DateI...
    - Tapestry and AJAX: Autocompleter and InlineE...
    - PropertySelection and IPropertySelectionMode...
    - The DatePicker and Shell Components of Apach...
    - Apache Tapestry: ASO and More Components
    - Apache Tapestry and DirectLink, IoC and DI
    - Making a CelebrityCollector with Apache Tape...
    - Apache Tapestry and Listener Methods, Condit...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 3 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek