Reputation: 1337
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?
Upvotes: 3
Views: 1014
Reputation: 412
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.
Upvotes: 3