Problem: Search engines indexing addon domain as a subdomain

Hi,

I started a new website using an addon domain and it is indexed by Google in three formats:

  1. domain.com
  2. domain.maindomain.com
  3. maindomain.com/domain

This never happened to me before. I found the following code on the web to make .htaccess redirects:

.htaccess in the domain.com folder:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^domain\\.com$ [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [L,R=301]

RewriteCond %{HTTP_HOST} ^www.domain.maindomain\\.com
RewriteRule ^(.*)$ http://www.domain.com/$1 [R=permanent,L]

RewriteCond %{HTTP_HOST} ^domain.maindomain\\.com
RewriteRule ^(.*)$ http://www.domain.com/$1 [R=permanent,L]

.htaccess in the maindomain.com folder:

RewriteEngine On
Redirect /domain http://www.domain.com

The effect is not yet seen since I inserted the code a few minutes ago.

Is this the best solution? Have you ever had a similar issue?

ademmeda,

What you’re describing is caused by the way that your host has setup your account. Mine are similarly setup but I don’t try to access the addon domains other than by (www.)addondomain.com.

Your .htaccess looks fine (albeit I’d recommend regex of .? and redirection which replaces /$1 with %{REQUEST_URI}) so I wouldn’t worry about that.

As for SEs, they take WEEKS to update. However, that said, if you can still access your domain by addon.main.com, then it’s possible that they will not remove that (despite your 301 redirections).

My advice is not to sweat the petty stuff - you’ve done what you can to resolve that situation.

Regards,

DK

Thanks for your comment David. I am afraid I didn’t understand this part: “albeit I’d recommend regex of .? and redirection which replaces /$1 with %{REQUEST_URI}”

ademmeda,

The use of (.*) can cause problems (generally, looping code) but the difference between Apache 1.x and Apache 2.x can also cause problems. The best reason to merely match anything then redirect to the %{REQUEST_URI} is that it already exists!

Better yet, your other code can be combined (or deleted) as you don’t need the redirection to domain.com in the maindomain’s .htaccess if you’re using

RewriteEngine On
RewriteCond %{HTTP_HOST} ^domain\\.com$ [NC]
RewriteRule .? http://www.domain.com%{REQUEST_URI} [L,R=301]

RewriteCond %{HTTP_HOST} ^www.domain.maindomain\\.com
RewriteRule .? http://www.domain.com%{REQUEST_URI} [R=permanent,L]

RewriteCond %{HTTP_HOST} ^domain.maindomain\\.com
RewriteRule .? http://www.domain.com%{REQUEST_URI} [R=permanent,L]

OR merely

RewriteEngine on
RewriteCond %{HTTP_HOST} !www\\.domain\\.com$
RewriteRule .? http://www.domain.com%{REQUEST_URI} [R=301,L]

Since what you want is www.domain.com, this will redirect only if not www.domain.com and it will then leave the {REQUEST_URI} (as seen in the domain’s directory) alone.

Regards

DK