Apache custom 404 page that returns 404 error

懵懂的女人 提交于 2019-12-12 14:22:51

问题


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.

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.

Is there a way to also return 404 when someone reaches the 404.php directly?


回答1:


I just whipped this up really quickly:

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

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.



来源:https://stackoverflow.com/questions/14549731/apache-custom-404-page-that-returns-404-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!