本帖最后由 fisher 于 2021-10-8 16:35 编辑
如果你不需要在CGI模式下运行,用header("HTTP/1.0 404 Not Found");就够了.
另外header("HTTP/1.0 404 Not Found");这个写法也不太好。文档里面也提到了这一句
I strongly recommend, that you use
header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found");
instead of
header("HTTP/1.1 404 Not Found");
I had big troubles with an Apache/2.0.59 (Unix) answering in HTTP/1.0 while I (accidentially) added a "HTTP/1.1 200 Ok" - Header.
可以适当改一下,兼容1.1和2
stripos(php_sapi_name(),'cgi') === 0 ? header('Status: 404 Not Found',true):header(($_SERVER['SERVER_PROTOCOL'] ?? 'HTTP/1.1').' 404 Not Found');
include('./404/404b.htm');
die; // 如果存在上层路由,建议直接宣布死刑
|