Desktop and Server Virtualisation Specialist 

Twitter LinkedIn E-mail
Precedence Technologies Ltd
Technology House, 36a Union Lane
Cambridge, CB4 1QB, United Kingdom
T: +44 (0)8456 446 800 / +44 (0)1223 359900

Using .htaccess files to customise error messages

At Precedence Internet, we use a webserver called Apache. This is most widely used webserver in the world. Apache is highly configurable and it is possible for some options to be set by the end user. This is performed by creating text file called .htaccess in your directories.

A brief guide is given below, but this is no substitute for having read the Apache documentation.

Setting up custom error pages

If someone accesses a page on your site that does not exist, then they will be sent a error message by the webserver. This will consist of an error code (404 for file not found), plus a small HTML page that will usually be displayed by the browser to the user. The page returned can be customised, so that the error message is more friendly. It could also redirect the visitor to your home page or site map. (Apache can also be set up so that the webbrowser is redirected to a different page which could even be on a different server. This is generally a bad idea, as the original 404 error will never be returned and so search engines may not realise they have visited a non-existent page).

To set up a customised error page for 404 error messages, simply create a .htaccess with the following line:

ErrorDocument 404 /404redirect.html
This will output the contents of 404redirect.html in the root of your website when a "404 file not found" error occurs.

You may also create custom error pages for other errors. Please see the Apache documentation for more details.

© Copyright Precedence Technologies 1999-2024
Time elapsed:0.019