Hide Your Site From Search Engines by using PHP 404 Header Code

You are reading this article because you want a surefire way to prevent your PHP pages from being indexed on search engines.

In earlier days, you would add a robots.txt file to the website to tell google fro example not to index, however, google stopped recognising robots.txt noindex in 2019.

If you are using PHP and want to prevent pages being indexed, the best way is to return a "silent" 404 error.

The code below added to any page will return a 404 error so if a bot is scanning your pages, they will see a 404 error and ignore it.

#####################
// throw silent 404 error everytime so this page is never indexed
// https://www.jucra.com/whmcs/knowledgebase/169/
#####################
header("HTTP/1.0 404 Not Found");

To deindex a whole site on WordPress, just add this code to the root index.php and this will force a 404 error which search engines hate.




  • 2 Users Found This Useful
Was this answer helpful?

Related Articles

Execute a cron task only on certain days with PHP

The code below can be used to execute code during certain days of the week. So, once a day, you...

Force download a file with PHP

This is a super helpful script if you need to force download a PHP file from another location on...