01 September 2010

Apache custom error pages (ErrorDocument)

Mostly neglected, the custom error pages from Apache don't offer much. They inform the user that a error occurred and that's it. We can use them for that purpose but improve the global user’s website experience that the default error pages offer.

Either in the virtual host configuration file or in .htaccess we can change the defaults to whatever combination of folder and file we desire.

Virtual host configuration example:
<Directory /www/example>
ErrorDocument 401 /errors/authorizationRequired.html
ErrorDocument 403 “Today you can’t come in, try tomorrow”
ErrorDocument 404 /errors/notfound.html
ErrorDocument 500 http://foo.example.com/errors/internalservererror.html
</Directory>

Normally when the user was already browsing the website and gets a error page, he clicks the browser back button. However, if he just got in to the website and the first page he gets its a error page, if he clicks the back button he leaves the website. So changing this 404 example:
<h2>Not Found</h2>
<h3>The requested URL /example.html was not found on this server.</h3>


to:

<h2>The page you are looking for doesn’t seem to exit anymore</h2>
<h3>Please use the search button to try and find the content you are looking for</h3>
< !- - And this play the search form here - - ><div>
</div><div>


will improve the users experience and might just keep them on the website. A simple change!

The Apache manual calls your attention to several bits of relevant and important information regarding this changes, so be sure to read it here.