The Perfect 404

by Ian Lloyd

57 Reader Comments

Back to the Article
  1. An error is an error. An exception should not be replaced by anything!

    If I download a web-document using a spider or robot I WANT the 404 as an error, not as a page. The ‘invention’ you show us here also break link-checkers, since they simply will find: aha, there is a document on this link, so all is fine.

    Usability is to be enhanced by applications, not by data-files. If the data is missing it is missing. If the programmer of the web-server wants to analyze the user-agent-string and send a special document: ok. If the browser does offer a better option: ok. But if the server sends a search- and report-form to the robot: bad!

    Copy & paste the code below to embed this comment.
  2. Read the provided links.  This is not a hack, this is an encouraged standard by Apache.

    ErrorDocument is an Apache directive that only customizes a standard Apache response containing important HTTP header information (404/301/etc).  The URL http://www.mydomain.com/error/404.html is not going to be written to your browser’s address bar. 

    Apache will serve the appropriate header information, i.e. the 404, and then provide this page in place of the incorrectly requested one.  Google does not catalog pages that give the appropriate 404 header information, nor 301, etc.  You can deny direct access to those files by simply adding a ‘Deny From All’ htaccess file in the error directory itself.

    The page that is served in conjunction with ErrorDocument is exactly the same as what you WANT and GET, this is only Apache’s way of allowing you to customize it’s look, feel, & functionality.

    If you’re still not convinced, read this:

    http://httpd.apache.org/docs/mod/core.html#errordocument
    http://httpd.apache.org/docs/custom-error.html
    http://httpd.apache.org/docs/misc/custom_errordocs.html

    Excerpt ::

    If all attempts to locate the content fail, Apache returns an error page with HTTP status code 404 (file not found). The appearance of this page is controlled with the ErrorDocument directive and can be customized in a flexible manner as discussed in the Custom error responses and International Server Error Responses documents.

     

     

    Copy & paste the code below to embed this comment.
  3. Better late than never.
    Ian and Andrew inspired me to write an ASP custom 404 page based on their ideas/design/style. Which is useful because I can actually use it for the health systems’ website that I manage. I believe simple and consistent options for all platforms could make 404 error pages useful across the board.

    eh – eNjoy…
    http://www.tastypopsicle.com/404.asp

    Copy & paste the code below to embed this comment.
  4. Okay, I added a search for an archival copy of pages that have been deleted from http://www.sfmuni.com

    Of course, there is no guarantee that Archive.org will have archived the particular page if it indeed ever existed.

    Example of a page we recently deleted.

    http://www.sfmuni.com/rid/cac/ca000706.htm

    Copy & paste the code below to embed this comment.
  5. from experience…

    if you use apache’s mod spelling then that’s it for server side (untill apache 2).

    if your isp has mod spelling turned on, you can turn it off with .htaccess but your error page (php etc) will still not run as the page has already been sent to mod spelling.

    Copy & paste the code below to embed this comment.
  6. MSIE/PC is per default set to
    “Show friendly HTTP Error Messages”
    thus making it impossible for ca. 95% of all users to benefit from the article’s idea as they are presented with what MSIE thinks is a good 404. (or 401 or the like)

    The default setting can be overruled easily but most users don’t (and wouldn’t know about it anyway).

    Web developers tend not to use MSIE for private surfing, (quite OK) so I guess that’s how the article came into beeing; good idea, but not fitting reality.

    By the way, I don’t see the point for relaying on client side scripting, server side offers the same possibilities here and wouldn’t exclude ca. 10% of all users.
    (some stats state that number for JS-less users)

    Copy & paste the code below to embed this comment.
  7. octet-stream solution (re Ian’s page 3 post)

    “…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.”

    IE violates the W3C rule of using MIME-type to determine how to handle a file; it uses the dot-extension instead. So IE will work fine with application/octet-stream (a default MIME type for some servers) while standards-compliant browsers will attempt to download the file.  The solution is to send .asp files out with the proper MIME type.

    In Apache, you would put this line in the .htaccess file of the root folder of your Web site (if you are the server master, you would put it in httpd.conf in /www/conf instead):

    AddType text/html .asp

    Other Web servers may use other syntax and files.

    —————————————————

    re: MSIE 404 default

    The MSIE default page for 404’s and other server errors only shows if the site-supplied 404 page is shorter than a certain number of bytes, 512 I believe.  If you want to show a custom page, you need to make sure it is longer than that length, so don’t be too terse.

    Copy & paste the code below to embed this comment.
  8. http://www.juicystudio.com/tutorial/xhtml/mime.asp#asp

    Please ignore the octet-stream portion of the previous post.  Of course, addType wouldn’t work for server-side generated pages.

    Copy & paste the code below to embed this comment.
  9. >The MSIE default page for 404’s and other
    >server errors only shows if the site-
    >supplied 404 page is shorter than a certain
    >number of bytes, 512 I believe.

    I tried this with MSIE6/WinXP, works well, 512b is the exact threshold.

    Thanks for the info, calling the article “useless for 95% of all users” was rash, I apologize.

    Copy & paste the code below to embed this comment.
  10. I read your article and then got to work on my site! Inspiration I tell you.

    Anyway, while researching the 404 custom error page thingy, I stumbled onto this site, http://www.plinko.net/404/ Someone has dedicated a section of their site to custom 404 pages. That’s amazing!

    Copy & paste the code below to embed this comment.
  11. One thing that annoys me almost everyday:

    Some people redirect every 404 Error to their Main 404 page. So I loose the original URL in the case I’d like to debug my incorrectly typed URL or to hack it in order to look what I can find around.

    So, whatever 404 page you put, please, don’t redirect the user somewhere else.

    Copy & paste the code below to embed this comment.
  12. What might be a good feature to have on 404 pages is a link to google’s cache, entering the adress that creates the 404 error. It might help the users to get what they are looking afterall.

    http://www.google.com/search?q=cache:[pagethatisnotfound]

    Copy & paste the code below to embed this comment.
  13. Good solid article with useful info. Check out Apple’s 404 error page (http://www.apple.com/gobbledeegook) – they seem to have really hit the nail on the head here.

    Copy & paste the code below to embed this comment.
  14. There is no reason for 404 error pages.

    In the years I am browsing the web, no single 404 page has helped me and your approach does not help either.

    The site is either searchable or not. If so, what does it cost to return to the top or the previous page and access a search box there ?

    404 is an error. An exception. It means: No document at given location.

    This is important ! Robots, Spiders, Downloaders use this to compute results. And these programs are the ‘other’ users of the web. You simply let them not read.

    Whenever I mirror a site with ‘wget’ I am very angry for all those 404-error-pages, that mean nothing to me. Even worse, this way sepcialized programs are not able to determine “holes” in a web-document.

    How with an error is being dealt is solely up to the clients programmer and user, not (!) to the web-designer.

    The web would be much nicer, if more web-designers would realize, that the internet is not a human-only territory.

    Copy & paste the code below to embed this comment.
  15. TEST

    Copy & paste the code below to embed this comment.
  16. TEST2

    Copy & paste the code below to embed this comment.
  17. Thank you very much for this great tutorial. It helped me very much.
    Good work.
    Greetig form Germany
    Dominik

    Copy & paste the code below to embed this comment.