【问题标题】:PHP auto_prepend and http 404 errorsPHP auto_prepend 和 http 404 错误
【发布时间】:2012-12-05 05:02:33
【问题描述】:

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

问题是当我想使用

输出 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。

希望有人能提供帮助。

【问题讨论】:

  • 首先告诉我们那个自动前置文件里面有什么。
  • @Jack,已经添加了上面的文件。
  • load.php 中的 PHP 标签周围有空格吗?
  • @Oscar,不,没有空格。

标签: php


【解决方案1】:

我在PHP header 404 not working找到了答案

<?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 输出。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-06-07
    • 1970-01-01
    • 2012-08-30
    • 2011-12-09
    • 1970-01-01
    • 2010-11-30
    • 1970-01-01
    • 2023-03-19
    相关资源
    最近更新 更多