htaccess 301 Permanent Redirect From Non-www To WWW

Discussion in 'Search Engine Optimization' started by Surf_Dude, Jun 2, 2008.

  1. #1
    Once again, the "canonical" problem. I haven't gotten it right yet.
    I would like to redirect ALL my files on one domain, from non-www to www.

    Is this htaccess redirect correct?

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

    I have seen about 5 versions of this, and I want to use the correct one.

    I copied some mod rewrite code before (gibberish to me), and it blew everything up, so I removed it immediately. I am not a programmer, just an HTML plodder. I know this should be simple, but not for me.

    I did the "fix" at Google, but what about the other engines?

    Thank you for your help.


    UPDATE:
    I tried the code out, and this was the result -
    "The page isn't redirecting properly"
    "Firefox has detected that the server is redirecting the request for this address in a way that will never complete.", and
    "This problem can sometimes be caused by disabling or refusing to accept cookies."
    I have never disabled my cookies.

    So, I immediately removed the htaccess file, since I cannot afford to have my pages not loading.
    Any ideas?
    I will work with my provider later today, after the traffic dies down.
     
    Surf_Dude, Jun 2, 2008 IP
  2. astup1didiot

    astup1didiot Notable Member

    Messages:
    5,926
    Likes Received:
    270
    Best Answers:
    0
    Trophy Points:
    280
    #2
    
    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^[b]yourdomain[/b]\[b].com[/b]$ [NC]
    RewriteRule ^(.*)$ [b]http://www.yourdomain.com/[/b]$1 [R=301,L] 
    
    Code (markup):
    Replace yourdomain with your domain name, leave the \ in the top part of the code.
     
    astup1didiot, Jun 2, 2008 IP
  3. nadlerz

    nadlerz Well-Known Member

    Messages:
    264
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    188