How to create a custom error page
Posted in Web Development on 20th October 2011
Creating a custom error page, also known as 404 page due to the server response returned when a page is not found is a question I see often around forums and the social sphere. So what I thought I'd do is make it easier for you by giving you a rundown of how to set up your system to handle this.
For this example we're going to be using a .htaccess file which will control the Apache platform. So this won't be IIS friendly. This won't be using the mod_rewrite module before you start to worry, so don't panic, I know many people out there find the mod_rewrite module tough to grasp (because it is). Although it is one of Apache's most powerful modules, it is also one of the most misunderstood. But luckily this small blog won't contain any nasty regular expressions or the like. So get your IDEs or text editors at the ready and we'll start now!
Basically, the aim of having a custom 404 page is to stop that horrible "The page cannot be Found" message and provide them with a lovely apology for potentially a mistake in your site, although it could just as easily be a typo too! Firstly we need a .htaccess file, or to edit an existing one. This file is literally named ".htacces" and you must be astute when looking through some systems, whether local or live servers, some don't show files starting with a '.' . So be vigilant. Now inside your .htaccess file you need to add the following line:
ErrorDocument 404 /404.html
This line declares that there is an error document present within the file system and what the error document is called. You can call the document whatever you want and it can be in whatever language you want too. For simplicity I chose HTML. The .htaccess file should be in your root directory, there it will affect all the files in that folder and filter down through your sub directories (if necessary). However if you want to display another 404 error inside a particular sub directory just place a separate .htaccess file in that particular folder.
Now the only thing you need to do is create your desired 404.html page, so when by either your mistake or users’ people try to find a non-existent page they get your custom page.
Nice and simple and a lovely touch!
Thank you so much for all your help and guidance with getting Louka Fine Finish Online and performing well, it's been a weight of my shoulders and a crucial step for my companies take! - Sean Stack






