One thing I’ve always found gave a nice little touch to any web site was to have custom error pages. Something a little friendlier than a standard 404 error can prevent a user from leaving your website due to frustration and confusion. They may think the whole domain was down and close the tab and proceed to the next Google search result Why not encourage the visitor to stay by providing them with an easy and efficient way to find what they’re looking for?
Note: You’re going to need to know the basics of setting up your own virtual host for Apache 2 to make use of this. If you don’t know how to do that you could probably find a tutorial on this blog if you try hard enough 😉
Open up the config file for your virtual host with your favourite text editor:
pico /etc/apache/sites-available/mywebsite.com
It should look something like this:
<VirtualHost *>
DocumentRoot /home/mypage.com/www/
ServerName mypage.com
ServerAlias www.mypage.com
ErrorLog /home/mypage.com/log/
CustomLog /home/mypage.com/log/
</VirtualHost>
Before the closing tag add links to your custom error pages, it should look like this:
ErrorDocument 403 /403.php
ErrorDocument 404 /404.php
Now save the file, restart apache by typing:
/etc/init.d/apache2 restart
If you haven’t created those custom pages yet, do so now or you’ll end up with a rather funny looking error page that tells you there was a 404 error while trying to find your custom 404 page. You can make it simple, just the general look and feel of your site with a friendly message of what happened. Or you can touch it up throw a custom search box that will allow them to find the proper file on your site. For that I will let Google give you the step-by-step.
For an example of a good 404 page, check out NiagaraForFree’s custom page.
Updated: March 10, 2009 for Ubuntu 9.04
A seasoned Senior Solutions Architect with 20 years of experience in technology design and implementation. Renowned for innovative solutions and strategic insights, he excels in driving complex projects to success. Outside work, he is a passionate fisherman and fish keeper, specializing in planted tanks.