A LIST Apart: For People Who Make Websites

No. 168

Discuss: The Perfect 404

Pages

 <  1 2 3 4 5 >  Last »

21 mod_speling

Just to add to what Josh L posted above, mod_speling can be good for taking care of some of the typos, though obviously is not ideal for those worried about performance. It does, however, check both spelling and capitalisation.

In addition, if you are do use a server side language to serve up your 404 pages (and other error docs), it can be extremely beneficial to have the page email you whenever an error doc is served. Ideally, include all request headers with it too, so you can track down the cause of the error.

posted at 07:01 am on January 18, 2004 by ILoveJackDaniels

22 Responses so far ...

Thanks for everyone who has commented so far. It has caught me off guard a little though, and as editor Erin pointed out, it’s also happening while I’m on travels and so I might not be able to respond in as timely a fashion as I’d like.

Thanks to James Cridland for building on the ideas I had in the article. I knew there would many other great ideas, so thanks for sharing.

As many have pointed it, there is an irony that in a piece about 404 errors, there has been another error in one of the example 404 pages, that being that the 404 page being served up is coming through as an octet stream. In IE it renders fine but on Firebird it prompts to save the custom 404 page as a file. If anyone knows how to remedy this, please add to the discussion.

Thanks also to Klaus for pointing out that Cross-site scripting was a potential problem. I don’t know how much of a problem this is – I do not have the mind of a hacker! – but I am not married to the notion that the script must be client-side. If the server config allows, I would favour server-side scripting which should, as I understand it, stop (or at least reduce) the spectre of cross-site scripting. If’ I’m wrong, please do tell ASAP.

posted at 08:22 am on January 18, 2004 by Ian Lloyd

23 404 eMail messages

Depending on your setup, it is helpful to add some server-side code into the custom 404 page to eMail the administrator information about the offending link. With PHP it is easy to create a mail message containing the URL (if they mis-typed it you can see what it was) the Referrer (so you can see if google has an outdated link or fix a link within yourown site), and other information like date/time, etc.

If you don’t have the ability to put this code in your custom 404 page, that’s OK. You can create a php file with just the mail function. Then in the HTML of the custom 404 page add a something like this in the head tag.

[removed][removed]

This contains the PHP mail function. If done properly, it will be called when ever someone hits the 404 page.

This will eMail you a heads-up that there is an error. If the offending link is from within the site, you can fix it. If the link comes from a search engine, you can temporarily re-create the link and point it somewhere else. You can even add a snippit of code to the top to tell the search engine the content has permenantly moved

header(“Status : 301 Moved Permanently”);
header(“Location: correct_link/”); /* Redirect browser */
exit;

Having a well designed custom 404 page is great, but after one person gets there, you should be making every effort that no one else does. Without any information about what caused the 404, someone is doomed to repeat the error.

posted at 09:43 am on January 18, 2004 by brian

24 Automatic emails aren't such a good idea

I have built a custom 404 page with some of the ideas here and toyed with the idea of an automatic email but a glance at my log files put me off the idea – most of the 404 errors come from script kiddies and worms looking for vulnerable web servers. Instead I plan to add an optional ‘Tell the webmaster’ form. Clicking submit without doing anything else will send the URL but they will have the option to add a comment and a return email.

Back to our current 404 page – Its all server-side using vbscript on an MS box. I use a text file that holds possible matches for the error URL. These include names for our larger directories, URLs for pages that have been moved, wrong URLs that published elsewhere.

If someone has a dud URL that points to somewhere in our ‘rules’ directory, they will be offered a link to the ‘Current rules and regulations’ contents page.

If its a known problem, eg a magazine has published a URL with a typo, we can offer the exact page.

The same idea on our search page gives ‘recommended links’ for our most common search terms.

I’ll have to look at the idea of dealing separately with typos and wrong referrals. What happens when people just chop off the end of the URL looking for an index page? We get a few of those.

If you have to deal with a Microsoft IIS server and would like the code, I’m happy to supply it.
http://casa.gov.au

posted at 07:32 pm on January 18, 2004 by Bruce Bowden

25 Script headers

If you are scripting a custom 404 page then it is critical to send appropriate headers. For example:

<?php
header(“HTTP/1.0 404 Not Found”);
?>

This will inform user agents (such as Googlebot) that the page is a 404.

posted at 09:52 pm on January 18, 2004 by = crutons.com =

26 Testing?

Does anybody have a good way of going to a URL and specifying a false referrer? Not sure how to test drive all the different pieces of this without, for example, convincing a search engine to link to a nonexistent page in my site…

posted at 11:44 pm on January 18, 2004 by nate cook

27 GOOD STUFF

Thought your article was great. Linked to it in this weeks newsletter I just sent out :)

posted at 02:44 am on January 19, 2004 by Aaron Wall

28 Remember data for analysis

One thing that is not mentioned in this otherwise good article is that you should have your system set up to send mails or other forms of data to your webmaster/system everytime a 404 fault is registered. This ensures a proactive approach if something is wrong and needs to be fixed i.e. someone in the marketing department has done a mailing with a wrong URL.

posted at 03:38 am on January 19, 2004 by Jesper Wacherhausen

29 More 404 Fun

No-one’s mentioned this site yet, the “404 Research Lab”: http://www.plinko.net/404/ . Tips and links to lots of custom 404 pages. Nice article btw, pity my ISP won’t let me write a suitable .htaccess file (sigh).

posted at 06:48 am on January 19, 2004 by Chris Hunt

30 Response To Nate Cook and the Article

Nate, you can just have a link to a non-existant page from another site. Just post it in a forum or something and click on it. That should work for testing purposes.

In response to the article, I think it has some good ideas. I will not use Javascript to implement this, but I undertsnad why the author did so. Thanks for taking the time to write this article, good ideas!

posted at 07:30 am on January 19, 2004 by Eric

Pages

 <  1 2 3 4 5 >  Last »

Discussion Closed

New comments are not being accepted, but you are welcome to explore what people said before we closed the door.

Got something to say?

Discuss this article. We reserve the right to delete flames, trolls, and wood nymphs.

Create a new account or sign in below if you’d like to leave a comment.

Remember me

Forgot your password?

Subscribe to this article's comments: RSS (what’s this?)