Here's the situation. My primary domain in a webhost is example.com (just a sample) I built a website subdomain.example.com Google has been indexing the website as subdomain.example.com However, Google is also indexing example.com/subdomain How to stop Google and other search engines from indexing example.com/subdomain? Is an .htaccess the solution? Or there is another way of fixing it? I am afraid I would be penalized for duplicate content.
That's the code Just place that line in your htaccess file. redirect 301 /subdomain/ http://subdomain.example.com Code (markup):
Yeah, but just test this one first. If it works, OK, add the others, if it doesn't, remove the line again.
It seems that the code is working. I still have to find out whether Google has stopped indexing the folder.
Good! Well, it'll be 301 redirecting to the subdomain, so eventually (in a couple of weeks) it should be gone from the googl index
An alternative is to specify the canonical address using a <meta> tag. http://googlewebmastercentral.blogspot.com/2009/02/specify-your-canonical.html