PHP auto_prepend and http 404 errors



我有Apache和PHP设置,我正在使用.htaccess文件将文件auto_prepend到任何输出。

问题是当我想输出 404 错误时使用

<?php header("HTTP/1.0 404 Not Found"); ?>

它仍然输出标头,因为auto_prepended文件已被处理。

.htaccess文件

php_value date.timezone 'Europe/London'
php_value auto_prepend_file load.php

load.php

<?php
    // Set the error reporting level (DEV)
    error_reporting(E_ALL);
    ini_set("display_errors", 1);
    // Load the configuration file
    include("config/config.php");
    session_start();
?>

因此,加载文件包含配置文件的包含,以便在加载的每个页面上设置它。

所以目前我有一些页面给出软 404 错误而不是实际的 404 错误,所以如果没有返回数据来浏览到/image/123,因为图像 123 实际上并不存在,我输出一个"这个图像不存在",所以这会给谷歌或任何其他爬虫带来问题,因为它可以从/image/123 ..../image/12222222333333444444 等...所以它实际上需要输出一个适当的 404。

希望有人能帮忙。

我在以下位置找到了答案: PHP 标头 404 不起作用

<?php
header("HTTP/1.0 404 Not Found");
exit("<h1>Not Found</h1>
The requested URL " . $_SERVER["REQUEST_URI"] . " was not found on this server.
<hr>");
?>

这将给出正确的 404 输出。

相关内容

最新更新