Forum Moderators: coopster

Message Too Old, No Replies

404 header not returning custom 404 page

         

JoaoJose

7:16 pm on Nov 29, 2005 (gmt 0)

10+ Year Member



Hi everyone.

I have a little problem. I've set up a custom 404 page using htaccess -> ErrorDocument 404 /notfound.html

Ok all works great but when I do a header("HTTP/1.0 404 Not Found"); on my scripts I do get the 404 but not the custom notfound.html page.

Who can I solve this?

Thks!

JoaoJose

3:10 pm on Nov 30, 2005 (gmt 0)

10+ Year Member



Still can find an answer for this...

Does anybody have an idea how to solve this? I'm sure someone has already faced this problem.

coopster

3:55 pm on Nov 30, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



That header() would go in the 404 page script (/notfound.html), not a referring page. That way the correct 404 header is sent out with the page when you direct a user to that page.

JoaoJose

4:52 pm on Nov 30, 2005 (gmt 0)

10+ Year Member




First of all thank you for your answer.

About what you said, that was not what I had in mind. My notfound.html page had no header() because the server would already send the 404 headers and then serve the notfound.html page.

I thought (wrongly now that I think about it)that by sending a 404 header with php that the server would serve the notfound.html. Off course this is stupid because I'me sending the header to the browser and the server doesn't know about it. Right?

Ok, so following your advice I've put the 404 header on the notfound.html page and it works. But how can I open the notfound.html page without sending headers first?

If I do an fopen("http://www.mydomain.com/notfound.html", "r") I get a 404 but not the notfound.html page and if I do a header("Location: [mydomain.com...] I'm doing a 302 when what I want is a 404...

How can I make this work?

whoisgregg

5:25 pm on Nov 30, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



if ($error){
include ($_SERVER["DOCUMENT_ROOT"]."/custom_404_page.php");
die;
}

First line of custom_404_page.php:

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

Added: I think this is what you are looking for. After rereading your last post again, I might be confused. :/

JoaoJose

8:39 pm on Nov 30, 2005 (gmt 0)

10+ Year Member



Yes that's it :) the include() is the way to go.

Thank you whoisgregg.