Search code examples
.htaccesshttp-redirectdnssearch-enginegoogle-index

How do I tell search engines not to index content via secondary domain names?


I have a website at a.com (for example). I also have a couple of other domain names which I am not using for anything: b.com and c.com. They currently forward to a.com. I have noticed that Google is indexing content from my site using b.com/stuff and c.com/stuff, not just a.com/stuff. What is the proper way to tell Google to only index content via a.com, not b.com and c.com?

It seems as if a 301 redirect via htaccess is the best solution, but I am not sure how to do that. There is only the one htaccess file (each domain does not have its own htaccess file).

b.com and c.com are not meant to be aliases of a.com, they are just other domain names I am reserving for possible future projects.


Solution

  • You can simply create a redirect with a .htaccess file like this:

    RewriteEngine on
    RewriteCond %{HTTP_HOST} \.b\.com$ [OR]
    RewriteCond %{HTTP_HOST} \.c\.com$
    RewriteRule ^(.*)$ http://a.com/$1 [R=301,L]