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:

With numerous addon domains.

I don't have a website setup for 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:

        <meta name="robots" content="noindex">

I now want to set the 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 root:

ErrorDocument 404 "<H1>Page not found</H1>"
ErrorDocument 404

But after running tests on 404 checkers, it still returns a "200 ok" response.

How can I make it respond 404?




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

    header("HTTP/1.0 404 Not Found");
    echo "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\">
            <title>404 Not Found</title>
            <h1>Not Found</h1>
            <p>The requested URL " . $_SERVER['REQUEST_URI'] . " was not found on this server.</p>
            <address>Server at " . $_SERVER['SERVER_NAME'] . " </address>

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).

  Options -Indexes

People are also looking for solutions to the problem: javascript - Where to put Js files in cakephp


Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.