PHP通过SSL返回200 OK状态头,而不是404错误
我有一个php脚本(test.php),它检查mysql中是否存在该页面,它应该返回404状态头,但它返回200 OK状态。这会导致控制台中出现软404错误 我试图修复,但根本不起作用。这是我的.htaccess。几个月前,我将我的站点迁移到SSL,并将所有流量从端口80重定向到httpsPHP通过SSL返回200 OK状态头,而不是404错误,php,.htaccess,http-status-code-404,Php,.htaccess,Http Status Code 404,我有一个php脚本(test.php),它检查mysql中是否存在该页面,它应该返回404状态头,但它返回200 OK状态。这会导致控制台中出现软404错误 我试图修复,但根本不起作用。这是我的.htaccess。几个月前,我将我的站点迁移到SSL,并将所有流量从端口80重定向到https RewriteEngine On ErrorDocument 404 /404.shtml RewriteEngine On RewriteCond %{SERVER_PORT} 80 RewriteC
RewriteEngine On
ErrorDocument 404 /404.shtml
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^(.*)$ https://www.example.com/$1 [R,L]
RewriteEngine on
RewriteRule ^([0-9]+)-([0-9]+)-([0-9]+)/pressrelease([0-9]+)\.htm$ test.php?pressid=$4 [L]
这是我的test.php
<?php
include_once('dbc.php');
$pid = strip_tags(mysql_real_escape_string($_GET['pressid']));
$rs_dirs = mysql_query("select id,name from categories order by name") or die(mysql_error());
$rs_press = mysql_query("select *
from press
where id = '$pid'
and approved='1'
") or die(mysql_error());;
$total = mysql_num_rows($rs_press);
if (mysql_num_rows($rs_press) == 0) {
header("HTTP/1.1 404 Not Found");
include '404.shtml';
die();
}
在代码中使用此代码:
if (mysql_num_rows($rs_press) == 0) {
http_response_code(404);
//and another staff here
}
您没有将实际状态代码设置为404
请参阅标题
功能的用法:
您的代码应该是:
header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found", true, 404);
还有一个替代功能:
我更喜欢使用上面的函数。因为它更详细地说明了你的意图。。它们不再得到维护。看到了吗?相反,请了解,并使用或-将帮助您决定使用哪一个。抱歉,不起作用。我看到一张空白页,不工作。我看到一个空白页。你有没有包括你的shtml或echo?在浏览器中查看网络。它应该显示404 not Found我检查了代码并且没有回音,但我认为问题在于htaccess重定向或报头在某处泄漏。
header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found", true, 404);
http_response_code(404);