Htaccess redirect to prevent indexing of subdomain didn't work

Hi,

On a previous post I asked about how to prevent search engines index my domain name as a subdomain but it seems my code didn’t work.

(http://www.sitepoint.com/forums/apache-configuration-199/problem-search-engines-indexing-addon-domain-subdomain-776510.html)

You can see from the below search that my site is still indexed as a subdomain to my main domain for the hosting.

site:thesoftwaretruth.com - Google Search

Do you have any idea about how should I modify my code?

Thanks,

Nail

Your code looks fine. You could make a few optimisations, but it should exactly what you want it to do. I really don’t know why google hasn’t propagated this by now. Maybe you could ask the guys over at our SEO forums?

I do see now btw that you don’t have [NC] at the end of the second and third RewriteCond. Did google cache in a different case than all lowercase? If so, that’s the problem. If not (i.e. google did store it all lowercase) I’m still out of ideas.

In case you’re wondering about those optimisations:


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

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

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

  • Put [NC] at the end of the second and third rewriterule
  • Properly escape all dots in URLs in the RewriteConds, and close the second and third one with a $
  • Use .? / %{REQUEST_URI} instead of ^(.*)$ / $1 because it’s more efficient

The first point could be the root of your problem (as stated above), the second and third just make stuff more efficient c.q. faster, but not behave differently.

Yes the code works, when I type configureweb.thesoftwaretruth.com, it redirects to configureweb.com. And here is the code in my .htaccess file:

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

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

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

In my experience, Google updates index results in about 1 week, but this time it seems not to be working. I didn’t have such a problem in my WordPress sites. This site is a custom coded one and I don’t know what is wrong.

This change doesn’t happen instantly, it takes a while for google to pick up on it. How long ago did you add this code to your .htaccess?

More than 3 weeks.

hm, that should be enough time for google to pick up on it. Have you confirmed the code works? I.e. when you request the domain that should not work, does the URL in your browser change to the URL you want it to be?
Also, can you post the exact code in your .htaccess please? Don’t spare us, just post all of it :slight_smile: