Forum Moderators: phranque

Message Too Old, No Replies

404 Errors not handled. why?

         

httpwebwitch

1:10 pm on Aug 17, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I have the following 4 lines in my .htaccess:

ErrorDocument 400 /400.php [L]
ErrorDocument 403 /403.php [L]
ErrorDocument 404 /404.php [L]
ErrorDocument 500 /500.php [L]

Each of these presents a friendly, nicely-branded page with a polite message describing the situation.
I should see that when I type in a bogus URL:
http://www.example.com/asdasdsad.php

But it's not working!

When I type in a bogus URL in Internet Explorer, I *do* get a 404 status, but I see the default IE 404 page.

Even when I go to the page directly, like so:
http://www.example.com/404.php
I don't see MY 404 page, I see Microsoft's 404 page.

The webpage cannot be found
HTTP 404
Most likely causes:
•There might be a typing error in the address.
•If you clicked on a link, it may be out of date.
What you can try:
Retype the address.
Go back to the previous page.
Go to and look for the information you want.

Same problem in Firefox - I see my page when I ask for /404.php, but with any bogus URLs I get an Apache message.

Not Found
The requested URL /asdasdsad.php was not found on this server.
Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
Apache/1.3.41 Server at example.com Port 80

The 404.php page begins by sending a 404 header, then follows with the page contents.

<?php 
header("HTTP/1.0 404 Not Found");
?>
<html>
<head>
...

What have I done wrong?

httpwebwitch

1:18 pm on Aug 17, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I found that removing [L] from each line solves it for Firefox:

ErrorDocument 400 /400.php
ErrorDocument 404 /404.php
ErrorDocument 500 /500.php
ErrorDocument 403 /403.php

But I'm still seeing the Microsoft page in IE

httpwebwitch

1:29 pm on Aug 17, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



(sigh) OK I figured it out.

IE doesn't respect your 404 page if the response is too small. The error page must be above an arbitrary size threshold, or the custom error page won't be shown. Without being too specific, it suffices to ensure that your custom error page is greater than 512 bytes.

So, I put this at the bottom of the page, and now my error pages are showing up in all browsers.


<!-- Would you like some PI?

3.14159265358979323846264338327950288419716939937510
58209749445923078164062862089986280348253421170679
82148086513282306647093844609550582231725359408128
48111745028410270193852110555964462294895493038196
44288109756659334461284756482337867831652712019091
45648566923460348610454326648213393607260249141273
72458700660631558817488152092096282925409171536436
78925903600113305305488204665213841469519415116094
33057270365759591953092186117381932611793105118548
07446237996274956735188575272489122793818301194912
98336733624406566430860213949463952247371907021798
60943702770539217176293176752384674818467669405132
00056812714526356082778577134275778960917363717872
14684409012249534301465495853710507922796892589235
42019956112129021960864034418159813629774771309960
51870721134999999837297804995105973173281609631859
50244594553469083026425223082533446850352619311881
71010003137838752886587533208381420617177669147303
59825349042875546873115956286388235378759375195778
18577805321712268066130019278766111959092164201989

-->

jdMorgan

1:43 pm on Aug 17, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Microsoft IE error page:

Microsoft is smarter than everyone else, and they know better what you (as a lowly "user") needs to see than any common Webmaster could possibly understand... :(

Therefore, MSIE replaces the Webmaster-specified error messages unless they are over a certain length (which varies depending on the error) and unless the "Show friendly HTTP error messages" option is un-ticked in the IE Advanced Options dialog box. Un-tick that option, and make your error page longer if necessary (by adding more descriptive/informative test or by padding it with non-printing characters as needed) to exceed 'power of two' boundaries (256 bytes, 512 bytes, 1024 bytes).

---

404 on requesting the 404 page:

A quick look at the Apache documentation for ErrorDocument shows that this directive does not recognize or allow 'flags' such as "[L]"

We wouldn't be so adamant in this forum about checking the documentation, except that errors in code posted on the Web are very common, and the costs of putting invalid commands into your server configuration files can be very high -- and long-lasting. In the very worst cases, a single typo could put you out of business.

For example, a very common error with ErrorDocument directives is to put a specify a URL instead of the local error document filepath. This causes the server to issue a 302-Found redirect to that new URL instead of the original error response code. Although this behavior is noted in the documentation, we see many Webmasters posting here wondering how and why they've 302-hijacked themselves right out of the search results...

ErrorDocument is part of the Apache core, and is documented in the "Core" section.

Jim