PHP标头(“HTTP / 1.0 404 Not Found”)返回200而不是404?

时间:2014-11-21 15:09:06

标签: apache .htaccess mod-rewrite http-headers php-5.5

header("HTTP/1.0 404 Not Found")似乎根本不起作用,因为我不断收到'REDIRECT_STATUS' => string '200'而不是'REDIRECT_STATUS' => string '404'

这是我的php代码,其中header("HTTP/1.0 404 Not Found")是mysql返回0结果的时候。

$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

因此,如果我输入数据库中找不到的页面,

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

它似乎是由RewriteRule ^([a-zA-Z0-9\-]+)/?$ index.php?url=$1 [L,QSA]

引起的

我有什么想法可以解决这个问题吗?

0 个答案:

没有答案