This will be a dry post for anyone not specifically looking for this info, but am so *thrilled* to finally have the answer to this dilemna that I had to write about it!
There has been much talk in recent years about the importance of signaling to the search engines that the ‘www’ and ‘non-www’ version of your site are one and the same. Since the search engines see these two urls as 2 different sites, you may be diluting your pagerank, or being dinged for duplicate content.
For months, I have been looking for the solution to the following problem: I have several websites, all hosted under one main hosting account. My main domain is www.fussybaby.ca, and all the rest of my sites are add-on domains, which are essentially sub-domains of www.fussybaby.ca. This means, for instance, my Her SEO site can be found as
www.fussybaby.ca/herseo
www.herseo.fussybaby.ca
www.herseo.com
(I’m thinking it may be able to be found by another url too, but am drawing a blank).
This means that there are at least 3 ways my [extremely sparse] content is being found - this means 3 version of the same content - aka DUPLICATE CONTENT. Uh-oh.
The problem has been that I have been unable to figure out how to 301 redirect an add-on domain. In the root folder of my Fussy Baby site, I had the following in my .htaccess folder:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^fussybaby.ca [NC]
RewriteRule ^(.*)$ http://www.fussybaby.ca/$1 [L,R=301]
This meant that anyone typing in fussybaby.ca, would automatically be redirected to www.fussybaby.ca. This is very good.
But, anyone typing in herseo.com, would NOT be directed to www.herseo.com. And that was NOT good.
I have fiddled for hours, trying to tweak the .htaccess file to have the add-on domain (herseo) redirect, without success.
Then tonight, thanks to this guy, it works!!
The code:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_HOST} ^fussybaby.ca [NC]
RewriteRule ^(.*)$ http://www.fussybaby.ca/$1 [L,R=301]
RewriteCond %{HTTP_HOST} ^(www\.)?herseo\.fussybaby\.ca [NC,OR]
RewriteCond %{HTTP_HOST} ^!www\.herseo\.com [NC]
RewriteRule ^(.*)$ http://www.herseo.com/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^herseo.com [NC]
RewriteRule ^(.*)$ http://www.herseo.com/$1 [R=301,L]
RewriteCond %{REQUEST_URI} ^/herseo($|/.*$)
RewriteRule ^.* http://www.herseo.com%1 [R=301,L]
I don’t even know exactly what it is about the code above that makes everything work, but it works, so I’m not asking any questions.
If you actually find this post interesting, you can read more at my post on htaccess www redirect.
If you’re using a wordpress blog it’s definitely a lot easier just to install the WP Super Cache plugin. It takes care of all that for you. Another good tool is woorank.com. They can tell you if your site is set up properly along with some free analysis of how well your site is optimized.
Better:
RewriteCond %{HTTP_HOST} ^(www\.)?two(\.com)?\.one\.com [NC,OR]
RewriteCond %{REQUEST_URI} ^/two\.com(.*)$ [NC,OR]
RewriteCond %{HTTP_HOST} ^two\.com [NC]
RewriteRule ^(.*)$ http://www.two.com/ [R=301,L]
RewriteCond %{HTTP_HOST} ^one\.com$ [NC]
RewriteRule ^(.*)$ http://www.one.com/$1 [R=301,NC,L]
Thinking of it, why not do it simpler?
Put this in the htaccess of your addon domain subdir and you’re set…
RewriteCond %{HTTP_HOST} !^www\.addon-domain\.com$ [NC]
RewriteRule ^(.*)$ http://www.addon-domain.com/$1 [R=301,NC,L]
One rule to catch them all!