【问题标题】:Apache custom 404 page that returns 404 error返回 404 错误的 Apache 自定义 404 页面
【发布时间】:2013-01-27 16:58:19
【问题描述】:

我的 apache (404.php) 上有一个自定义的 404 错误页面,它可以正常工作,但是如果有人或任何搜索引擎请求 /404.php 页面,服务器会返回 200 (OK),因为该页面确实存在。

我已将Disallow: /404.php 放在我的robots.txt 文件中以防止Google 将该页面编入索引,但我想返回404,包括此页面请求。

当有人直接到达404.php 时,有没有办法也返回 404?

【问题讨论】:

  • 您在 .htaccess 文件中提供的链接是绝对链接 (server/404.php) 还是相对链接?
  • 相对。 ErrorDocument 404 /404.php

标签: apache2 http-status-code-404 custom-error-pages


【解决方案1】:

我很快就完成了这个:

<?
 header("HTTP/1.1 404");
 echo "ERROR"; // Put the contents of your 404 page here.
?>

我在 Chrome 中检查了它,这将在标题中返回一个 404 代码,并让您在页面的其余部分写入您想要的任何内容。只需将header 函数放在页面开头即可。

【讨论】:

    猜你喜欢
    • 2013-03-01
    • 2016-04-25
    • 2013-09-16
    • 2014-01-30
    • 2015-03-18
    • 2015-08-01
    • 2011-01-01
    • 2020-03-22
    • 2018-12-26
    相关资源
    最近更新 更多