141 php header http-status-code-404
if (strstr($_SERVER['REQUEST_URI'],'index.php')) {
header('HTTP/1.0 404 Not Found');
}
Run Code Online (Sandbox Code Playgroud)
为什么不这样做?我得到一个空白页面.
Ala*_*orm 306
您的代码在技术上是正确的.如果您查看该空白页面的标题,您将看到404标题,其他计算机/程序将能够正确识别未找到文件的响应.
当然,您的用户仍然是SOL.通常,404s由Web服务器处理.
问题是,一旦Web服务器开始处理PHP页面,它已经通过它将处理404的点
除了提供404标头之外,PHP现在还负责输出实际的404页面.
Eva*_*ark 78
if (strstr($_SERVER['REQUEST_URI'],'index.php')){
header('HTTP/1.0 404 Not Found');
echo "<h1>404 Not Found</h1>";
echo "The page that you have requested could not be found.";
exit();
}
Run Code Online (Sandbox Code Playgroud)
如果您查看最后两条回波线,那么您将看到内容.您可以根据需要自定义它.
Bob*_*ger 74
这是正确的行为,由您来创建404页面的内容.
蜘蛛和下载管理器使用404标头来确定文件是否存在.
(带有404标题的页面不会被谷歌或其他搜索引擎索引)
但普通用户不会查看http-header并将该页面用作普通页面.
Sil*_*ian 16
对于记录,这是全案例处理程序:
<?php
header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found");
header("Status: 404 Not Found");
$_SERVER['REDIRECT_STATUS'] = 404;
?> <!-- 404 contents below this line -->
Run Code Online (Sandbox Code Playgroud)
小智 14
加载默认服务器404页面,如果你有一个,例如为apache定义:
if(strstr($_SERVER['REQUEST_URI'],'index.php')){
header('HTTP/1.0 404 Not Found');
readfile('404missing.html');
exit();
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
144541 次 |
| 最近记录: |