weballey logo
left Misc - error documents right
homesearchsite mape-mail
meta tags
special chars
special chars list
< custom errors >
      Most web servers create rather bland error documents, or one with the logo of your provider. This short tutorial will teach you how to create your own error documents.
    First you will need to make sure your provider and web server support the use of .htaccess files. Most do, but some system administrators disable them, in favour of their own documents, or for security reasons.
    The most occurring error is the '404 not found error'. Often urging you to write the owner of the website, telling how you got there. Nobody ever does this, so you might as well leave that part out. Let's see how we can tell the server to use our own document instead.

ErrorDocument 404 /notfound.html

    First you create a .htaccess file containing the text above. There are three arguments on one line. The first 'directive' tells the server we want to use our own 'error document'. The second is a number, telling on which error to do something. This number is a server response code. There are several. The most used is '200 OK'. You never see this one, the browser knows the document is found and that he can display it.
    The 400 range concerns the document errors, 404 tells the the browser the requested document could not be found. A simple 404 message would be enough, the browser knows it can display a '404 not found error'. Most servers do send an alternative html document however.

Error document
    This is where the third argument comes in. This tells the server to display the file 'notfound.html' in the web root of your site. The same directory where your home page 'index.html' is found. If you would create more error documents, you could put them in a seperate directory, like 'errors', or 'errordocuments'.
    The error document itself needs some attention too. Make sure you use absolute references for images and links. Why? When a document in a subdirectory is not found, the error document will be displayed in its place. If the error document uses relative links, they will originate in that same subdirectory. Probably causing another 404 not found error, when clicked. Or displaying the wrong document, when a file with the same name exists, where the link leads.

    In my error document I put references to the home page, my local search engine, and a site map. This should be enough to get the lost visitor on his way. You could also do more exotic things. Like using a cgi script, registering the error, the page concerned, the referring page, etc. This could be helpfull if you cannot access your server log files, to detect these errors.

No .htaccess
    In case your provider does not support .htaccess files, there may be other solutions. Some have their server setup to display a standard page, like 'missing.html' or 'notfound.html' from your user directory.

Prevent errors
    Keep in mind that 404 errors are generally caused by yourself. Carelessness in file naming and links, or moving files or sections of your site, without checking all links to it. Also other people may have linked to your site, resulting in dead links for them.

left Copyright © Gerben Hoekstra - All rights reserved right