October 23rd, 2006
What happens when a user is sent a link to your site (or manually types your URL) there’s a typo? What happens if you have a broken link on your site? What happens when a search engine brings up results for your site but it’s for a page you’ve removed?
The visitor is presented with their browsers (or webhosts) ghastly 404 page with no link to the correct page. The chances are the visitor may not bother to try and strip the URL down to your domain and search for the page, they’ll just close you page and look else where.
What can be done to avoid this? A custom 404 page! And example can be seen at MyPetsite.co.uk/ - enter anything random at the end and the custom 404 page will appear.
The .htaccess technique.
This method is designed to work on an apache server with html pages.
This technique can also be used to create different error pages for 403 - forbidden, 401 - unauthorised, 501 - Unable to connect to server etc. However, if simplicity is what you are after than you can have all such errors can be directed to the same page.
Create a text file in notepad or you favorite plain text editor. Enter the following line:
ErrorDocument 404 http://yourdomain.com/your404page.html
Next save the file, doesnlt matter what you call it as we’ll be renaming it. Locate the file on your computer. Ensure you can see the full filename including the extention (e.g. File.txt) If you can’t see the extention in windows file explorer choose menu option
In WinXP
TOOLS > FOLDER OPTIONS.. VIEW (tab) >
And untick the option HIDE EXTENTIONS OF KNOWN FILE TYPES.
Next rename the file to “.htaccess” notice there is nothing proceeding the dot.
Upload the file along with your custom 404/error page(s) to the folder you want to feature the custom pages. If you want all your sites/pages on your server to have the same set of cusom error pages then put it in the root. I have multiple sites on the same server so I have a different .htaccess file in each folder (pointing to different error pages).
Please note this technique has the following Cavet. It does not support bad links to .php or .asp pages or pages which contain a scripting string at the end. (i.e. It doesn’t pick up error pages that have a ? Followed by some session data or search term).
As people rarely type a question mark and data after, it isn’t usually a major problem if your trying to catch user typos.
If you site makes use of links to .php/.asp pages or is not on apache then you will need to use different technique (check back on this site for further techniques) .
Filed under Ask the Guru, Tutorials |