Forum Moderators: coopster

Message Too Old, No Replies

custom 404

         

pixelhub

9:20 pm on Feb 24, 2007 (gmt 0)

10+ Year Member



hi how can i create a custon 404 error page hat displays the url the user tried access.

i have added this

ErrorDocument 404 [*******.co.uk...]

to the .htaccess file withing the test folder and in the 404.php file i have the line of code

<?php echo $_SERVER['REQUEST_URI'];?>

which should show the url that was requested, but instead it just shows 404.php

what am i doing wrong

thanks

cameraman

12:01 am on Feb 25, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The offending page is in:
$_SERVER['REDIRECT_URL']

pixelhub

11:25 am on Feb 25, 2007 (gmt 0)

10+ Year Member



Cameraman, thanks for the reply.

I think I’m missing something that’s obvious.

If I use this line of code (and it the only code) in the 404.php file

<?
echo "Document not found...\n<br>";
echo $_SERVER['REDIRECT_URL'] . "<br>";
echo $_SERVER['REQUEST_URI'] . "<br>";
?>

the 'REDIRECT_URL' displays nothing and the 'REQUEST_URI' displays

test/404.php

all help is much appreciated

thanks

LunaC

2:08 pm on Feb 25, 2007 (gmt 0)

10+ Year Member



Not sure if this is the problem or not, but it should be written like this in the .htaccess:

ErrorDocument 404 /test/404.php

Using a full URL will usually make the server not respond with a proper 404. Check the response headers to be sure. If you use Firefox, Live HTTP Headers is a great extension for this.

jdMorgan

3:06 pm on Feb 25, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



LunaC is correct. As stated in the Apache ErrorDocument [httpd.apache.org] documentation, specifying a canonical URL as the error page target will result in a 302 external redirect. Therefore, the client will invoke a *new* HTTP request, directly requesting the error page URL. The context of the original error will therefore be lost.

Use ErrorDocument 404 /test/404.php as LunaC recommended.

Jim

pixelhub

7:26 pm on Feb 25, 2007 (gmt 0)

10+ Year Member



hi thanks for the help

i have replaced the full url in the .htaccess file so no it reads

ErrorDocument 404 /test/404.php

and have placed it within the test folder but i no longer get the custom 404 page.

edit...

i have just checked it in firefox and it works great but not in ie7?

in ie it just displays the standard

"The webpage cannot be found" 404 error message.

why does this happen how can it be solved?

thanks again

jdMorgan

7:38 pm on Feb 25, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Flush your browser cache(s) before testing any changes to your server configuration. Otherwise, your browser will show you the page it has previously cached without sending a request to your server.

IE7 Tools->Internet Options->General /Browsing History->Delete->Temporary Internet Files /Delete Files

Jim

adb64

8:49 pm on Feb 25, 2007 (gmt 0)

10+ Year Member



Also make sure the 404.php script sends out enough data.
In case of an error IE will show its own error page when yours in not large enough. I think the limit is around 512 bytes or so (configurable in IE somewhere).
So add some extra text (or spaces) to you custom errorscript to make it larger.

pixelhub

8:55 pm on Feb 25, 2007 (gmt 0)

10+ Year Member



Thanks every one it now works.

I cleared the cache but I still received to standard IE 404.

Then I read that IE won't display the custom 404 if the page size is too small? With the only code on the 404 page being what is above the page size was under 1KB, so I added some text to pad it out and it works.

I don't know why IE this does but it does

Thanks again for all your help

Cheers

pixelhub

9:09 pm on Feb 25, 2007 (gmt 0)

10+ Year Member



adb64 . you got there before me.

:)

jdMorgan

9:47 pm on Feb 25, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



More info on "Friendly Error Messages" from Microsoft: Description of Hypertext Transport Protocol Error Messages [support.microsoft.com]

Jim