string '200' instead of 'REDIRECT_STAT" /> string '200' instead of 'REDIRECT_STAT" /> string '200' instead of 'REDIRECT_STAT"/>

PHP header("HTTP/1.0 404 Not Found") return 200 instead of 404?

507 Views Asked by At

header("HTTP/1.0 404 Not Found") does not seem to be working at all because I keep getting 'REDIRECT_STATUS' => string '200' instead of 'REDIRECT_STATUS' => string '404'.

This is my php code where header("HTTP/1.0 404 Not Found") is when the mysql return 0 result.

$this->item = $this->Database->fetchRow($sql,array(
            ...
        ));

if($this->item === false)
{
    header("HTTP/1.0 404 Not Found");
    echo "PHP continues.\n";
    include  WEBSITE_DOCROOT.'local/template/base/article/not_found.php';
    die();
    echo "Not after a die, however.\n";
}

.htaccess,

RewriteEngine on
RewriteRule ^([a-zA-Z0-9\-]+)/?$  index.php?url=$1 [L,QSA]
ErrorDocument 404 /projects/mywebsite/path/index.php

So if I type in the pages that cannot be found in the database,

http://website/path/foo/ --> 200 but should be 404
http://website/path/foo/boo/ --> 404 correct
http://website/path/foo/boo/too/ --> 404 correct

It seems that it is caused by RewriteRule ^([a-zA-Z0-9\-]+)/?$ index.php?url=$1 [L,QSA]

Any ideas how I can fix this?

0

There are 0 best solutions below