php - How to set primary domain on a VPS to 404 to remove from Google index?
I have a VPS hosting package with a primary domain:
www.exampleprimary.com
With numerous addon domains.
I don't have a website setup for exampleprimary.com so after going on it earlier, I learnt that it was showing an "index of/" and showing a list of all my addon domains. I do not want this to happen so I added a index.html to show a blank domain instead.
I then learnt Google had indexed my primarydomain and still shows all the addon domains, so I want to remove it from the index.
I made the index.html file:
<html>
<head>
<meta name="robots" content="noindex">
</head>
<body></body>
</html>
I now want to set the exampleprimary.com domain to show a 404 error to ensure Google bots eventually remove the domain from the index. But I can't get the domain to return a http 404 response. I created a .htaccess and added to the exampleprimary.com root:
ErrorDocument 404 "<H1>Page not found</H1>"
ErrorDocument 404 http://www.exampleprimary.com/
But after running tests on 404 checkers, it still returns a "200 ok" response.
How can I make it respond 404?
Answer
Solution:
If you want to do it with PHP you can remove your index.html and then add an index.php file with something like this
But Is going to be better if you do this kind of configurations in your webserver.
It seems that you are using Apache, you were seeing "Index of" I guess because directory listing was enabled, disable that option in apache and then you will see a default 404. Add this to your .htaccess file (or better in your Vhost definition).