The importance of error pages …

search engine optimization, techie tips

404 error page in IE7 So, you’ve built this super cool website. You are really pleased with it and you set it live expecting great things. But wait, the client has rung you to say that when they search for their site on google their old listings are still there but when they click through they get ‘404 Error – Page Not Found’.

What do you do? Well there are a number of things you can do. You could wait 3 – 4 weeks for the listings to drop out of Google, if you have a google webmaster account you could log in and manually delete every link that is now dead (which would again take time to be approved) or, if your website is hosted on an Apache server, you could modify the .htacces file…

So what is a .htaccess file?

Basically, it’s a text file where you can list commands for an Apache server. Telling it to behave in a certain way depending on certain conditions. .htaccess is actually a file extension rather than the name of a file. Don’t misunderstand though, your file on your server needs to be called .htaccess not file.htaccess. The name stands for hyper text access and is a ASCII text file and you can create a .htaccess file using any basic text editor.

So what can you do with a .htaccess file?

.htaccess files are extremely powerful. The main reason they are used is to either re direct pages or to create pretty url’s. I’m not going to go into detail about what pretty url’s are in this post. I’ll save that for another time.

If you build all of your websites using Wordpress or a similar open source content management solution, then you probably won’t need to know anymore about .htaccess files other than this is the file you are editing when you change your permalinks.

About those ‘page cannot be found’ errors …

So why should you worry about these errors?
No website is absolutely perfect 100% of the time. There could be any number of reasons why somebody could get an error page on your site. You could have recently re arranged your site and not updated a link correctly, deleted a page and accidentally left the link in place or any number of other reasons.

Error pages re assure the visitor that they have come to the right place. If they were browsing your website anyway and clicked on a link that is broken, chances are, they would use the back button in their browser and there is no harm done. But if they found the page through a search engine you have potentially lost a new visitor, and maybe even new business. The browser back button would take them back to the search engine.

Creating your own custom error pages

Getting around 404 Errors using Wordpress is really simple. All you have to do is add a page to your theme called 404.php that uses your styling and your custom error message. If an error occurs Wordpress will automatically look for that page first. For more information on creating error pages have a look at the Wordpress codex here

If, like me, you also build completely bespoke websites and applications, then knowing how to avoid error pages adds a massive amount of usability to any site you build.

Its not a complicated process, all you have to do is create your custom error page and upload it to your server. Once you’ve done that open your .htaccess file within any text editor and add these lines to it.


ErrorDocument 400 /notfound.php
ErrorDocument 401 /notfound.php
ErrorDocument 403 /notfound.php
ErrorDocument 404 /notfound.php
ErrorDocument 500 /notfound.php

If you prefer you can add the absolute url to the page. For example:


ErrorDocument 400 http://www.kirstyburgoine.co.uk/notfound.php

This is especially useful if you have pages within sub folders within your site.

That’s it! You can test your error page by typing anything after your domain name. If it loads your error page instead of a standard ‘not found’ page. You have successfully setup error pages.

You can see mine in action here:

Wordpress Error page: http://www.web-ramblings.co.uk/test

Custom Error page: http://www.kirstyburgoine.co.uk/test

Have fun!

TwitterFacebookDelicious
DiggRSSStumbleUpon

Tags: , , , , ,