A LIST Apart: For People Who Make Websites

No. 168

Discuss: The Perfect 404

Pages

 1 2 3 >  Last »

1 The travels of Mr. Lloyd...

Ian Lloyd is out and about in Australia and will have intermittent Internet access for a few days after the publication of this article. Should you have any questions for him, please be patient. All will be answered in the fullness of time.

posted at 04:13 pm on January 16, 2004 by Ed. Note

2 Avoiding 404s

The best way to deal with 404s is not to have them in the first place. Every time I move a page on my site I leave behind a file in the same place with the same filename that tells the user the page has been moved, and gives them the new link.

The alternate method is to use .htaccess files to automatically redirect the user to the correct place. You can redirect based on wildcards, so whole directories can be catered for. No more 404s.

posted at 04:43 pm on January 16, 2004 by Chris Hester

3 mod_speling

Checking URL spelling might help reduce the number of 404s. Apache can do this: http://httpd.apache.org/docs/mod/mod_speling.html

posted at 04:45 pm on January 16, 2004 by Josh L.

4 301 and 302

Arg!

I’ve stated this before, but I’ll say it again, as it seems that people overlook this.

“expired links” ie. links that used to exist but now exist in a new location [vs. mis-typed links] should be redirected via an HTTP ERROR 301 “file permanently moved” or an HTTP ERROR 302 “file temporarily moved”. These are seamless re-directs and will automatically update personal bookmarks and allow search engine crawlers to update their entries.

301 and 302 errors are obviously a better choice than presenting the visitor with a page telling them that something doesn’t exist, with the bonus of “fixing” old search engines without begging Google et al to change them for you. 404s should only be used in cases where the URLs are totally invalid due to human typographic errors, or the content doesn’t exist on the site anymore

posted at 07:07 pm on January 16, 2004 by CM Harrington

5 Proper HTTP errors

Actually, if the URL used to be valid but isn’t anymore, and the content does not exist at any other location, the proper HTTP status code is 410, not 404.

Also, Ian, the sample links to accessify.com attempt to download the page rather than displaying it. I’m using the latest nightly build of Firebird. It works properly in IE6.

posted at 07:19 pm on January 16, 2004 by Mark

6 hmm.

i didn’t think this would be a very informative article, since error pages are very easy and basic, but there were some pretty useful tidbits stashed.

kudos.

posted at 09:01 pm on January 16, 2004 by corey

7 .htaccess "Redirect Permanent" a

If your site is running on top Apache and you’re allowed to use .htaccess files, create a file called, ‘.htaccess’ and put the below (between the snips)in there:

[snip]
Redirect Permanent /the/old/page.html http://heythatsyoursite.com/the/new/page.html
[snip]

(all on one line, mind)

Save this file in your root public_html directory (the same place you put, say, a robots.txt file)

That way, the user will never see an error page, which is what a “404” is (an error smarty) Yes, a visitor will never know that they need to, “update their bookmarks”, but when’s the last time you did that? That’s what I thought…

If you want to get really techy, you can use the “RedirectMatch” thingy, like this:

[snip]
RedirectMatch ^/the/old/directory http://heythatsyoursite.com/the/new/directory
[/snip]

If you have some sort of odd fetish and know regex’s like the back of your hand (hairy hands up!), you’ll know that the caret (^) means: “match the beginning of a line”.

We follow that with a directory. That means, any request to the directory will be redirected to a different directory.

Finally, notice that you can use ANY url for,“http://heythatsyoursite.com”. For instance, if you move your entire site, or, a portion of your site – say your knitting tips are REALLY taking off and deserve their own site, it’s really no problem now, init?

Cheers,

Justin Simoni

posted at 09:48 pm on January 16, 2004 by Justin Simoni

8 "sample links ... attempt to download the page"

That’s because the server returns Content-Type: application/octet-stream instead of text/html in the HTTP headers. Mozilla doesn’t know what to do with an octet-steam, so it pops up a Save to Disk box.
I’ve sent a bug report to accessify.com.

posted at 10:21 pm on January 16, 2004 by Rahul Narain

9 .htaccess; 410; .Archive.org

.htaccess

I have updated .htaccess when moving files and directories around, but I ususally do it in the old subdirectory so as to reduce the load on the root .htaccess; perhaps this is overkill, and may be harder to maintain.

410

Not sure how to make Apache spit this out. I’d still probably want to show the same error page. Actually, we show the same error page for 403 as for 404, simply to keep the content simple for the end-user.

Archive.org

If we can’t find a trace of the file, I wonder whether it would make sense to offer to search for the page at archive.org, with the warning that the page is presumably out of date.

posted at 12:24 am on January 17, 2004 by Charles

10 A good 404 example

Dunstan at 1976design has a great <a title=“1976design 404” href=“http://www.1976design.com/blog/ndex”>example 404.

posted at 03:28 am on January 17, 2004 by Will Pate

Pages

 1 2 3 >  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?)