Google is indexing main domain despite 301 redirect to subdomain

Google is indexing main domain despite 301 redirect to subdomain - .htaccess files are extremely useful in many cases for users who either do not have root permissions or for users who simply aren't comfortable in making changes in their web server's configuration file. Trying to debug .htaccess not working isn't always the easiest thing to do, however, hopefully by checking the discuss below mentioned about htaccess, 301-redirect, , , .htaccess common problems as well as the troubleshooting tips, you'll have a better grasp on what you may have to modify to get your .htaccess file running smoothly.Problem :


I had applied 'redirect 301' from main domain to subdomain and Google had indexed sumbdomain (and links under it) for years. Now, for some reason Google has started indexing the main domain while keeping all of subdomain links indexed except one - subdomain.maindomain.com (this one has been de-indexed and replaced by maindomain.com). Main domain shouldn't even be listed in Google results and subdomain.maindomain.com should remain there. There are about 12 results like maindomain.com/folder listed in Google results as of now, I'd like them removed but without using robots (read somewhere it's bad for SEO if combined with 301 redirect?) or requesting removal in Google Webmasters Tools (I'm worried Google will de-index whole site).



Following is the .htaccess config for reference:



RewriteEngine on


AddHandler application/x-httpd-php54s .php

RewriteCond %HTTP_HOST ^website.com$ [OR]
RewriteCond %HTTP_HOST ^www.website.com$
RewriteRule ^/?$ "http://subdomain.website.com/" [R=301,L]


There's no robots file as of now.


Solution :

It looks like you are only redirecting the home page. Your rewrite rule states that for the redirect to work, the path of the URL may only contain an optional slash.



So, if Googlebot somehow gets links deeper into the site, it would be able to crawl the site except for the home page.



You should change your rewrite rule to the following:



RewriteRule ^(.*)$ http://subdomain.website.com$1 [R=301,L]


I found this website to test: http://htaccess.madewithlove.be/



Then I create a test



.htaccess



RewriteEngine on

RewriteCond %HTTP_HOST ^domain.com$ [OR]
RewriteCond %HTTP_HOST ^www.domain.com$
RewriteRule ^(.*)$ http://sub.domain.com/$1 [R=301,L]


Urls tested:




Additionally, if you would like to do some further testing, give the htaccess tester tool a try. It allows you to specify a certain URL as well as the rules you would like to include and then shows which rules were tested, which ones met the criteria, and which ones were executed.

Comments

Popular posts from this blog

Rewrite in Mediawiki, remove index.php, .htaccess

.htaccess rewrite wildcard folder paths from host

Using .htaccess to set a cookie and 301 redirect