IE and Custom Error Pages

An oft overlooked part of one's website is the 404 page. Many of the visitors who see your 404 page will most likely be first time visitors looking for something in particular. Rather than show them some drab looking "404 Page Not Found" message you might want to consider providing something a little more useful. For instance, my 404 page contains this site's archives - listed both monthly and topically as well as a short message about what just happened. I also included a few suggestions in addition to my contact info. Your 404 page should be given the same attention as your home page. Consider it the gateway to your site.

The problem is, although all modern browsers will display your custom 404 page, Internet Explorer may not. Since v5, IE insists on using it's own built-in error page. There are some people who claim that upon arriving at a non-existent URL Internet Explorer will quickly size up your custom error page and if it is less than 512 bytes in total size it will render its own error page. The solution then seems obvious - ensure your custom error page is greater than 512 bytes. Sounds good but it is not foolproof as I found out. As I said earlier, I have plenty of information on my error page and at one point even included a bunch of nonsensical text commented out in the source code which guaranteed the page was greater than 512 bytes yet IE still at times insisted on using its own error page. It was hit and miss.

So how then do we force IE to use your custom error page? Add the following code to the top of 404.php,

<?php ob_start(); ?>
<?php header("HTTP/1.1 404 Not Found"); ?>

About the author
Len has been blogging for over 10 years and is a rabid WordPress fan. In addition to blogging here you can find him writing the occasional article and toiling away in the forums at WeblogToolsCollection.com. He also hangs out at the WordPress support forums lending a hand where he can. You can find his political scribblings at RiteTurnOnly.com

12 Responses to “IE and Custom Error Pages”

  1. meowmie says:

    I searched high and low for a solution to this problem (and tried everything from making sure that I have 512 bytes to adding a line in the .htaccess file), but none of it worked until I came upon your post. Thank you so much!

  2. Alex F says:

    Thank you very much for sharing the helpful tip.
    I have been searching for a solution and it worked perfectly.

  3. Jake says:

    Thanks for the pro tip - I was having this same issue. It seems a little odd, though. Why does IE8 want this separate header information?

  4. Captain Errorpage says:

    thanks for the solution, it seems IE still behaves however it wants to even in 2010! thankfully people like you are on hand to help out! :)

  5. Thanks so much! I was completely baffled by this issue. Firefox kept reading my WordPress custom 404 properly but IE8 just ignoring it over and over. I tried everything I could think of and nothing worked until adding those couple php lines and voila. It works!

  6. Cees says:

    Too bad the trick doesn't seem to work outside of WordPress (??).

    I added the extra code to my custom 404 page, which works splendid in FF, but gets ignored by IE8....

    Weird he?

Leave a Reply

CommentLuv Enabled