Forum Moderators: coopster

Message Too Old, No Replies

PHP header("HTTP/1.0 404 Not Found");

IE will not display the output after this

         

chrisjoha

1:16 pm on Jul 20, 2005 (gmt 0)

10+ Year Member



I use mod_rewrite to rewrite URLs. If the receiving index.php doesn't find content to serve for the URL, it issues something along the lines of:

header("HTTP/1.0 404 Not Found");
file_get_contents('404.html');

It works like a charm except in IE. IE displays its regular 404 page. Can I bypass this behaviour and still send a 404 response?


(I'm very sorry if this is a double post. I'm pretty sure something like this must exist in here, but all the google in the world couldn't help me find it ;) )

lobo235

2:54 pm on Jul 20, 2005 (gmt 0)

10+ Year Member



You could try using header( 'Status: 404' ); instead of header("HTTP/1.0 404 Not Found");

Maybe this will produce different results.

chrisjoha

3:07 pm on Jul 20, 2005 (gmt 0)

10+ Year Member



Well, that helps serving up the page, but apache logged the request with status 200 :¦

JamShady

3:10 pm on Jul 20, 2005 (gmt 0)

10+ Year Member



I send a status 200 back to represent a successful page load (from the browser's point of view, only the user need know that it's actually an error page)

chrisjoha

3:34 pm on Jul 20, 2005 (gmt 0)

10+ Year Member



I don't know if that makes any sense. If the page (or rather, the content) is not found, it's not found. Don't matter if you load another page to help the visitor. I need the 404 status in my server logs so I can diagnose and add support for often misspelled urls and so on.

Besides, I don't want search engines to think that an erraneous url has valid content. my 404 page is not something I need listed and ranked in the search engines ;)

JamShady

3:48 pm on Jul 20, 2005 (gmt 0)

10+ Year Member



Well, I suppose it's what you use your 404 for. I personally use it to make up a lot of pages. My 404 page generates many different pages depending on the URL being accessed. Basically, in many cases I treat the 404 page as an automatic generator for a page that doesn't actually exist, and it works quite well for me.

chrisjoha

4:04 pm on Jul 20, 2005 (gmt 0)

10+ Year Member



I see. I use mod_rewrite to redirect all requests to index.php to achieve the same effect. This way I can use 404 for what it's there for - missing pages :)

mykel79

10:17 pm on Jul 20, 2005 (gmt 0)

10+ Year Member



There is a "feature" in IE - if a server's 404 page is shorter than a certain amount of characters, IE will display its own 404 page. So the solution would be for you to make a longer 404 page.

jdMorgan

11:28 pm on Jul 20, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



mykel79's got it right -- make the page larger to overcome IE's "friendly error messages" - ahem - "feature". IIRC, you'll need 512 bytes or more.

Do not, under any circumstances, return a 200-OK, 302-Found, or 307-Moved Temporarily response for a request for a missing page; To do so is to risk confusing search engines spiders and hurting your site's rankings.

Ref: RFC-2616 Hypertext Transfer Protocol -- HTTP/1.1 [w3.org]

Jim

chrisjoha

6:39 am on Jul 21, 2005 (gmt 0)

10+ Year Member



That fixes it! Thanks a bunch. My 404 was only 112b during testing, so it got overridden by ie. :)