Redirect domain.com -> www.domain.com
Posted by Staff Team, Last modified by Andy Williams on 04 March 2007 09:57 PM

Google and most search engines see domain.com and www.domain.com as two different sites/pages. The problem is if you get links to your site, some with the www and some without, your total number of links isn't the true total. It's split between the two. Using .htaccess and mod_rewrite, you can do a 301 redirect to the www version.

Below is some code that will help:

rewriteEngine on
Options +FollowSymLinks
RewriteCond %{HTTP_HOST} ^domain.com$
RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,L]

The first line turns the rewrite thing on, if it was off.

The second line is needed if you are using FrontPage with Mod_rewrite. To ensure FrontPage works with mod_rewrite, you needed to change the "Options None" to "Options +FollowSymLinks" just in each of the htaccess files of the 3 following FP directories only: _vti_bin ; _vti_bin /_vti_adm ; and _vti_bin/ _vti_aut

The third line checks for the host. The ^ means the beginning and the $ means the end.

The forth line, no checking what comes after the host, will forward any directories/files from domain.com to your domain with the www. The $1 is the variable that hold the directories/files, so yourdomain.com/some/directory/file.html would have $1 equal to some/directory/file.html. The R=301 forces a 301 permanent move redirect. Google will then see it as one domain. The L says it's the last rule. If you add other rules and leave off the L, it would go through them all before finally redirecting.
(354 vote(s))
Helpful
Not helpful

Comments (0)
Post a new comment
 
 
Full Name:
Email:
Comments:
CAPTCHA Verification 
 
Please enter the text you see in the image into the textbox below (we use this to prevent automated submissions).