Redirecting mysite.com to www.mysite.com automatically

Discussion in 'Site & Server Administration' started by Kevin3d, Jan 23, 2009.

  1. #1
    Hi,

    Let's say I have a website http://widget.com and I have specified in my hosting company's control panel a server alias of http://www.widget.com, so that the site can be accessed via either of those 2 URLs. Is there a way i caan set it so that someone going to http://widget.com/pagename is automatically sent to http://www.widget.com/pagename (the exact same page).

    I tried a 301 redirect but it doesn't seem to work:

    redirect 301 http://widget.com http://www.widget.com

    One of the issues is that I say 10 inbound links to http://widget.com and 20 inbound likes to http://www.widget.com and I'm guessing it might be better for SEO to have all the inbound likes to the exact same domain name.

    Thanks in advance.
     
    Kevin3d, Jan 23, 2009 IP
  2. Kevin3d

    Kevin3d Peon

    Messages:
    9
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Ok,

    so I tried:

    redirect 301 / http://www.widgets.com/

    and got a "re-direct loop", which makes sense.
     
    Kevin3d, Jan 23, 2009 IP
  3. Kevin3d

    Kevin3d Peon

    Messages:
    9
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Got what I wanted by putting in the .htaccess file:

    Options +FollowSymLinks
    RewriteEngine On
    RewriteBase /
    RewriteCond %{HTTP_HOST} !^www.widgets.com$ [NC]
    RewriteRule ^(.*)$ http://www.widgets.com/$1 [L,R=301]


    wow...I should talk to myself more often.
     
    Kevin3d, Jan 24, 2009 IP
  4. pr0t0n

    pr0t0n Well-Known Member

    Messages:
    243
    Likes Received:
    10
    Best Answers:
    10
    Trophy Points:
    128
    #4
    Hehe I'm glad you got it resolved. You can do it this way as well:

    
    RewriteEngine On
    RewriteCond %{HTTP_HOST} !^www\.
    RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
    
    Code (markup):
    Cheers! :cool:
     
    pr0t0n, Jan 24, 2009 IP