301 Redirect for non-www to www

Discussion in 'Search Engine Optimization' started by Webase, Mar 25, 2006.

  1. #1
    Hi, my main page contains the www. and I know that makes a difference, should I do a 301 redirect if you don't type www? Will that help me, in SEO terms?

    If it helps, how do I do it?

    I noticed I have a PR5 with and without the www, so I guess I could have a boost on www, right?
     
    Webase, Mar 25, 2006 IP
  2. fsmedia

    fsmedia Prominent Member

    Messages:
    5,163
    Likes Received:
    262
    Best Answers:
    0
    Trophy Points:
    390
    #2
    I do it and I like to do it so that way if anyone were to link to domain.com instead of www.domain.com, I still get all the benefits. Take a look at this yes, www.yes-www.org
     
    fsmedia, Mar 25, 2006 IP
  3. pcdoc

    pcdoc Active Member

    Messages:
    690
    Likes Received:
    36
    Best Answers:
    0
    Trophy Points:
    70
    #3
    add

    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteCond %{HTTP_HOST} !^www\.free-phphosts\.com [NC]
    RewriteRule ^(.*) http://www.free-phphosts.com/$1 [L,R=301]
    </IfModule>

    to .htaccess then store in server root

    then test with

    phphosts.com

    and

    www.free-phphosts.com
     
    pcdoc, Mar 25, 2006 IP
  4. Webase

    Webase Peon

    Messages:
    53
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Hi, thanks for the quick anwser, I already have the lines
    RewriteEngine On
    RewriteBase / on my htaccess

    Can I just add
    RewriteCond %{HTTP_HOST} !^www\.free-phphosts\.com [NC]
    RewriteRule ^(.*) http://www.free-phphosts.com/$1 [L,R=301]
    ?
    Or do I need to add those lines
    <IfModule mod_rewrite.c>
    </IfModule>

    I don't really understand the code you give me, but why both have www?

    Well, I only added
    RewriteCond %{HTTP_HOST} ^free-phphosts.com
    RewriteRule (.*) http://www.free-phphosts.com/$1 [R=301,L]
    I think it worked, right? free-phphosts.com automatically goes to www, did I succeed, lol?
    How about /index.php goes to / ?

    By the way, is there any difference from http://www.free-phphosts.com/ and http://www.free-phphosts.com ?
     
    Webase, Mar 25, 2006 IP
  5. digital1

    digital1 Well-Known Member

    Messages:
    517
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    125
    #5
    Not trying to hijack your thread here, Webace, but rather then start a whole new thread I thought I might ask for some help implementing this into my .htaccess file too.
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>
    Code (markup):
    If some kind soul would be generous enough to help me out then you will be handsomely rewarded with rep.
     
    digital1, Mar 25, 2006 IP
  6. digitalpoint

    digitalpoint Overlord of no one Staff

    Messages:
    38,334
    Likes Received:
    2,613
    Best Answers:
    462
    Trophy Points:
    710
    Digital Goods:
    29
    #6
    digitalpoint, Mar 25, 2006 IP
  7. kurtsfar

    kurtsfar Guest

    Messages:
    37
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #7

    Don't forget the no-case(NC) flag in the rewritecondition that makes it case insensitive.

    The example below it has "! - sign" which means "if not", in the RewriteCond.

    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteCond %{HTTP_HOST} !^www\.free-phphosts\.com [NC]
    RewriteRule ^(.*) http://www.free-phphosts.com/$1 [L,R=301]
    </IfModule>
    Code (markup):
    You can just as well do it like this:

    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteCond %{HTTP_HOST} ^free-phphosts\.com [NC] 
    RewriteRule ^(.*) http://www.free-phphosts.com/$1 [R=301,L] 
    </IfModule>
    Code (markup):

    And if you are putting .htaccess in your root folder you don't need "RewriteBase", unless - I think - if mod_alias or mod_userdir are
    involved...


    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^free-phphosts\.com [NC] 
    RewriteRule ^(.*) http://www.free-phphosts.com/$1 [R=301,L] 
    </IfModule>
    Code (markup):
    If you already have RewriteEngine On you don't need that again. Also if you already have the if module statement the only interesting parts lines are these:

    RewriteCond %{HTTP_HOST} ^free-phphosts\.com [NC] 
    RewriteRule ^(.*) http://www.free-phphosts.com/$1 [R=301,L] 
    Code (markup):
    Just put them within your existing
    <IfModule mod_rewrite.c>
    </IfModule>
    Code (markup):
     
    kurtsfar, Mar 25, 2006 IP
  8. digital1

    digital1 Well-Known Member

    Messages:
    517
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    125
    #8
    Thanks, kurtsfar. I had to tinker a little with the code to get it to work with mine but it pretty much did the trick. :)
     
    digital1, Mar 25, 2006 IP