Forum Moderators: phranque

Message Too Old, No Replies

Custom 404 - htaccess fine with 404.html but not 404.php

         

Karma

11:01 am on Nov 5, 2010 (gmt 0)

10+ Year Member



I'm trying to create a custom 404 page that:

a) displays a user friendly message
b) writes the current (404'd) URL to a database

However, something must be wrong as I am only able to display 404.html - when I change the file-name to 404.php I get the browser default.

So, the following works fine:

ErrorDocument 404 /404.html

...but:

ErrorDocument 404 /404.php

gives me "Ooops! This link appears to be broken" (browser default).

Both files exist in the root folder (404.html and 404.php) with exactly the same content (simple html).

I've tried moving these away from the root but I get the same problem, 404.html is fine but .php is not.

Any ideas?

coopster

1:16 pm on Nov 7, 2010 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



What happens when you try to bring up the 404.php page in your browser? Does it work? If not, well ... from the Apache docs on ErrorDocument [httpd.apache.org]:

Although most error messages can be overriden, there are certain circumstances where the internal messages are used regardless of the setting of ErrorDocument. In particular, if a malformed request is detected, normal request processing will be immediately halted and the internal error message returned. This is necessary to guard against security problems caused by bad requests.

Karma

4:16 pm on Nov 8, 2010 (gmt 0)

10+ Year Member



When I type the URL (404.php) directly in to the browser, it doesn't works either.

What I'm not understanding is why request is 'malformed' - seeing as 404.html works fine.

jdMorgan

12:56 am on Nov 30, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Then take one more step back, and re-name 404.php to test.php, and request test.php from your server.

This will allow you to separate script execution problems from error-handling problems.

If you are testing using MSIE, then that browser will serve its "friendly" HTTP error messages unless your server serves error pages that are larger than 256 or 512 bytes -- I don't remember which. If you want to do serious server testing, using a different browser (not IE) would be a good idea...

Jim