404 and IE

Wed 26, October 2005 0:58:31

This is a nice tip for people having problems with custom 404 pages in Internet Explorer. If you don’t know what a 404 error is, then let me explain in the shortest form possible:

It’s what your browser gets when it can’t find the page you requested.

There, a very low-tech explanation that goes straight to the point. If you want a “real” explanation, I suggest www.plinko.net.
Take a look around - they have everything you need to know about 404, and then some.

When I was making my very own custom 404 page for this blog, which should be a reasonably easy task, I stumbled upon a really weird problem. No matter how much I tried, I could not see the page in Internet Explorer. It was working fine in Firefox, but IE kept showing me its own standard “Page not found”. I went googling on the problem and it became clear that this is a known issue. IE is a little bit too smart for its own good – if you dig through the options, you’ll find a little gem named “Show friendly HTTP error messages”. If this is enabled, then IE can choose to ignore the content of error pages and show its own version of them. And, this option is enabled by default (of course…).

A good workaround is to prevent your browser from knowing that your page is actually a 404 page, and you can do that by forcing the return of a code 200.
How exactly you do that? Well depends on which technology you are using for generating the pages. Basically, you must be able to control the HTTP headers being returned. In the case of PHP (which I use in this case), I could solve my problem by adding this block of code:

<?php
  header("HTTP/1.1 200 OK");
  header("Status: 200 OK");
?>

The two different styles of declarations are just to ensure that will work, regardless of what version of PHP is being used. Note that this must absolutely be the first thing on the page!
You can check my 404 page. If I did my job right, you should see it, even in IE.

2 Responses to “404 and IE”

Jonathan wrote a comment on Mon 17, April 2006

Problem with that - you can’t add the site to google sitemaps!

You have to “correct” this, by making it a real 404 page again!
Then google can deal with your sitemap.

Rui wrote a comment on Sun 14, January 2007

Yes, that’s partially true. But now Google sitemaps has other ways to validate you using META tags, so this is still ok

Care to comment?