Forum Moderators: coopster

Message Too Old, No Replies

custom 404 error page problems

solution to one 404 problem

         

MonkeyBreath

3:12 pm on Apr 21, 2004 (gmt 0)



Whilst trying to get my custom 404 page working, i encountered some problems.

Here are a few tips that may save you time if you are in a similar situation:

1. Check to see whether PHP is running as a CGI interpreter or an Apache module. Do this by running the phpinfo() function to check how your server is configured. You can tell if it's running as a module 'cos the "Server API" variable shows a value of 'Apache'. Else, "Server API" is set to "CGI".

If it's running as a CGI version, making a custom 404 page is going to be a little bit more tricky. See this thread [webmasterworld.com...]

(My hosting package ran PHP4 as a CGI version by default but allowed me alter the configuration, using the .htaccess file, to tell it to run as an Apache module)

2. Create a file called 404.php (or your choice of filename) in the directory where you keep your public html files. Then fill it with some test content.

VERY IMPORTANT : Put a sizable amount of test-content into this file. e.g about 300 characters, at least, of 'sfdfndfdnf ' or 'blah blah blah'. This is because, (I quote from [phpbuilder.com...] )"You simply need to make sure your 404 script is generating enough
output. For some weird reason M$ decided to substitute their own 404 page
if the remote server sends less than a certain amount of bytes. Right now
I don't recall exactly what that magic number might be. Try experimenting
a bit and let us know.
-Rasmus"

(This where i went wrong and it took me ages to discover the problem. I had previously just put 'this is a 404 page' - and it didn't show up for the reasons explained above.)

3. Place this directive in your .htaccess file:
ErrorDocument 404 /404.php
Where '/404.php' is the file you want to use as the custom 404 page.

(I came this forum after searching google whilst trying to solve a problem i had with customizing a 404 error handling page on my php4 apache virtual server
and read the discussion here:
[webmasterworld.com...]
I tried to add this comment to that thread, but was not allowed by the forum settings - the topic was too old)

coopster

9:46 pm on Apr 21, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld, MonkeyBreath!

hehe. that almost sounds like an insult rather than a welcome. Rest assured, it is an honest welcome ;)

CompressedAir

5:09 pm on Apr 24, 2004 (gmt 0)

10+ Year Member



Good post.
Pay careful attention to the "You simply need to make sure your 404 script is generating enough
output." I could imagine why IE kept giving me it's own error page instead of mine. So make sure your test page is nice and big :)
Took me a while to figure that one out. Knowing ahead of time would have saved me some time and head-bashing! :)