返回 404 错误的 Apache 自定义 404 页面 [英] Apache custom 404 page that returns 404 error
问题描述
我的 apache (404.php) 上有一个自定义的 404 错误页面,它可以正常工作,但是如果有人或任何搜索引擎请求 /404.php
页面,服务器将返回 200 (OK)
,因为页面确实存在.
I have a custom 404 error page on my apache (404.php) and it works normally, but if someone or any search engine requests the /404.php
page, the server returns 200 (OK)
, because the page actually exists.
我已经将 Disallow:/404.php
放在我的 robots.txt
文件中,以防止 Google 将该页面编入索引,但我想返回 404,包括到此页面请求.
I have already put the Disallow: /404.php
on my robots.txt
file to prevent Google from indexing that page, but I'd like to return 404, including to this page request.
当有人直接到达404.php
时,有没有办法也返回404?
Is there a way to also return 404 when someone reaches the 404.php
directly?
推荐答案
我很快就想到了:
<?
header("HTTP/1.1 404");
echo "ERROR"; // Put the contents of your 404 page here.
?>
我在 Chrome 中检查过,这将在页眉中返回 404 代码,让您可以在页面的其余部分写入任何您想要的内容.只需将 header
函数放在页面的开头即可.
I checked it in Chrome, and this will return a 404 code in the header, and let you write whatever you'd like to the rest of the page. Just put the header
function at the beginning of the page.
这篇关于返回 404 错误的 Apache 自定义 404 页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!