Forum Moderators: coopster

Message Too Old, No Replies

can't get header to load default 404 page

header, 404

         

ElectronMan

1:50 am on Nov 19, 2007 (gmt 0)

10+ Year Member



Hi. I am using mod_rewrite to send all traffic through the index page. If a page isn't there, then my index.php page should load the 404 page. I don't have a custom 404 page. I use header("Status: 404 Not Found"); because header("HTTP/1.0 404 Not Found"); was giving a 404OK response. So now, the 404 Not Found gets sent but then the page stays blank instead of loading the default 404 page. How do I get it to load the default 404 page? I thought thats part of what header("Status: 404 Not Found"); is supposed to do.

Here is the header response I get:

Date: Mon, 19 Nov 2007 01:26:22 GMT
Server: Apache
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Pragma: no-cache
Keep-Alive: timeout=15, max=74
Connection: Keep-Alive
Transfer-Encoding: chunked
Content-Type: text/html

404 Not Found

jdMorgan

2:10 am on Nov 19, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



No. index.php must output the '404 page' as well as the status header. Of course, this could be an "included" external file if you wish.

Jim

ElectronMan

3:01 am on Nov 19, 2007 (gmt 0)

10+ Year Member



How do I get Apache to serve (or write out with php) the default 404 page after the header?

[edited by: ElectronMan at 3:01 am (utc) on Nov. 19, 2007]

jdMorgan

3:22 am on Nov 19, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Apache has already entered the content-handler API phase to run your script, so everything that happens is up to your script. Write the 404 header, then write the HTTP content-body by "printing" whatever it is that you want the 404 page to show in the browser. Or use PHP to include and print an external file with that page's HTML code in it -- either way.

(I'm posting as an Apache guy. Hopefully, a real PHP person can be more helpful.)

Jim

PHP_Chimp

7:07 pm on Nov 19, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



<?php
header ("HTTP/1.0 404 Page Not Found");
?>
<html>
<head>
<title>My site is broken</title>
</head>
<body>
<p>Some excuse about my broken links...</p>
</body>
</html>

Will give you a nice error page with a great bit of text ;)

Well maybe you want to change the html...

Seeing as you are using Apache why not use the ErrorDocument to do it properly and not try to have a page that returns correctly also issuing a 404 response? i.e.
ErrorDocument 404 /path_to_404.php

<edit>
After my smart reply...you need to make sure that the 404 page has enough content. As IE uses its own error page for pages that dont have a content of more than 250 bytes or something like that (google for teh exact amount, as I cant remember, but it is small).
This shouldnt be an issue...unless you actually use my code as above.

[edited by: PHP_Chimp at 7:15 pm (utc) on Nov. 19, 2007]