Welcome to WebmasterWorld Guest from 107.22.7.35

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

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

php, header

     
5:08 am on Jan 11, 2008 (gmt 0)

10+ Year Member



I'm just trying to test to see if my header 404 is working in PHP and I have this:

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

But when I go to that page, nothing comes up. Is this something I have to explicitly set in Apache? I just want to be able to show a 404.

Thanks.

5:33 am on Jan 11, 2008 (gmt 0)

10+ Year Member



It seems to show up for IE but not Firefox... hmmm...
5:57 am on Jan 11, 2008 (gmt 0)

WebmasterWorld Administrator coopster is a WebmasterWorld Top Contributor of All Time 10+ Year Member



See if this thread helps ...
[webmasterworld.com...]
1:55 pm on Jan 11, 2008 (gmt 0)

10+ Year Member



Well, I tried using the include as per the instructions in the thread you suggested but the 404 still doesn't show up in Firefox. I even tried it on a separate website that I have and it still isn't showing up. I think I might try just redirecting to an actual page that loads instead of throwing a 404. I'm still curious as to why it's not displaying in Firefox though... it seems rather odd. Thanks for the help.
6:56 pm on Jan 11, 2008 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member



Strange.
Have you got liveheaders for firefox? If so then check what the response from the page you are calling is.

In apache you should have something like -


ErrorDocument 404 /some_dir/my_error_page.php

So that when you go to example.com/doesnt_exist/bla_bla.not
apache redirects that request through to /some_dir/my_error_page.php

You may find that if you have used the full address for the apache ErrorDocument then you will get a 302 status, as http//something (: removed so there isnt a link...is there any way to stop that?) will result in an external redirect and a 302 header, then it gets to that page and has a 404 header thrown at it. Would be very confusing.

So check the headers returned by your 404 page then it may be an apache set up issue, as the php looks fine.

7:39 pm on Jan 11, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Firefox has no built-in default 404 display, so if your PHP script sends no HTML output in addition to the 404 header, nothing will be displayed by the browser.

Internet Explorer on the other hand uses a default informative 404 page if there is no HTML content returned along with the 404 header.

Apache's 404 configuration only applies to plain old .html files that haven't been handled by a filter (e.g. PHP).

10:48 pm on Jan 11, 2008 (gmt 0)

WebmasterWorld Administrator coopster is a WebmasterWorld Top Contributor of All Time 10+ Year Member



But you can use the Apache error_docs if you have an Alias setup or at least know the path to the resource. Set up an Alias [httpd.apache.org] to the error_docs directory and then you can use them on a 404 by calling a url_not_found function. Something along these lines ...
function url_not_found() 
{
header('HTTP/1.x 404 Not Found');
include realpath($_SERVER['DOCUMENT_ROOT'] . '/../error_docs/not_found.html');
exit;
}

Don't forget to make the error_docs available to PHP parsing if there is a base directory restriction [php.net] in place.
 

Featured Threads

Hot Threads This Week

Hot Threads This Month