Apache 404 page that returns 404 error
I have a 404 error page on my apache (404.php) and it works fine, but if someone or any search engine requests the page /404.php
, the server returns 200 (OK)
because this page actually exists.
I have already put Disallow: /404.php
in my file robots.txt
to prevent Google from indexing this page, but I would like to return a 404, including on this page request.
Is there a way to return 404 when someone reaches 404.php
directly?
I just whipped this up quickly:
<?
header("HTTP/1.1 404");
echo "ERROR"; // Put the contents of your 404 page here.
?>
I tested it in Chrome and it will return a 404 in the header and let you write whatever you want on the rest of the page. Just put the function header
at the beginning of the page.