Home arrow Apache arrow Page 4 - Custom Error Pages with Apache

Maintaining and updating error pages - Apache

Nobody enjoys seeing an error page. It's worse if the error page gives you little or no information to help you find the page you were trying to reach. Fortunately, there are ways to configure Apache so that your visitors need never feel so abandoned. This article explains how to set up custom error pages with Apache.

TABLE OF CONTENTS:
  1. Custom Error Pages with Apache
  2. Creating a custom error page
  3. Internationalized error pages
  4. Maintaining and updating error pages
By: Dan Wellman
Rating: starstarstarstarstar / 13
April 03, 2006

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

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
 

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

APACHE ARTICLES

- Apache Unveils Cassandra 1.2
- Apache on ARM Chips? Dell and Calxeda Help M...
- The Down Side of Open Source Software
- VMware Unveils Serengeti for Apache Hadoop
- SAP Takes Steps to Improve Hadoop Integration
- Looking to Hone Apache Hadoop Skills?
- How to Install Joomla on WAMPP
- Working with XAMPP and Wordpress
- GUI Available for Apache Camel
- Reduce Server Load for Apache and PHP Websit...
- Creating a VAMP (Vista, Apache, MySQL, PHP) ...
- Putting Apache in Jail
- Containing Intrusions in Apache
- Server Limits for Apache Security
- Setting Permissions in Apache

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: