HomeApache Page 2 - Custom Error Pages with Apache
Creating a custom error page - 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.
Configuring Apache to serve customized error pages is extremely easy; there is a section of the httpd.conf file devoted to this. It takes just one directive per error to achieve. If you open the conf file and scroll right down to almost the very bottom of section two, you’ll see the section you need to edit:
By default, these directives are commented out, but all you need to do is un-comment each directive and then change the path to point to your own error page:
ErrorDocument 404 /errordocs/404error.html
Quite simply, this statement is broken down into the directive name, the error code and the path to the document you wish to use. You could substitute this last part simply for text enclosed within double-quotes to specify the text to be displayed on the page, but this is hardly an improvement on the default messages themselves. Also, this path could alternatively be the path to a script. As you can see, I’ve put my error documents into a separate folder in my site’s directory structure.
So, very quickly and easily then, you can simply create a series of your own error documents, to cater for the most common server error codes and add the required directive to the conf file. In addition to enhancing the user experience by giving a more pleasant error response, you can also introduce consistency across your site by using CSS to make the pages look like the regular pages of your site. You should also make sure that the pages fit in with other policies in effect on your site; if you pride yourself on your adherence to the accessibility guidelines, for example, you need to ensure that your site map and a help page are linked to from the error pages and that any other applicable guidelines are satisfied. This is common sense anyway, and if you want to provide better error handling from a user’s perspective, you’ll probably want to link to different parts of your site anyway to prevent the error pages from being dead end pages with the user given no choice but to reach for the Back button.
For some different examples of custom error pages, you can view both extremes; at Google for example, the custom error pages simply contain a Google logo and a very brief message. They aren’t overly helpful, but they are consistent with the overall design of the site. Ebay, on the other hand, provides a very large and highly customized error page, with many links and tons of information.