Redirecting all pages of website to non www to www domain

Discussion in 'Site & Server Administration' started by computerzworld, Aug 1, 2009.

  1. #1
    Hello,
    I want to redirect my website automatically from non-www to www domain. Here is what I have done.

    rewritecond %{http_host} ^example.com [nc]
    rewriterule ^(.*)$ http://www.example.com/$1 [r=301,nc]

    This works for just the url not for other pages like if I write example.com/index.htm then it doesn't redirect to http://www.example.com/index.php however it redirects example.com to http://www.example.com. but doesn't redirect the urls with the pages. How can I redirect every url of a website from non-www to www? Please help me. Thanks in advance.
     
    computerzworld, Aug 1, 2009 IP
  2. National

    National Peon

    Messages:
    42
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    but doesn't redirect the urls with the pages

    what do u mean by the above statement
     
    National, Aug 2, 2009 IP
  3. computerzworld

    computerzworld Active Member

    Messages:
    214
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    58
    #3
    what I want to say that if I type example.com in the browser then it redirects it to www.example.com but if I type example.com/index.php then it doesn't. I have tried with appending $1 in the htaccess but still its not redirecting all the pages. So, is it possible to redirect all the pages of website from non www to www?
     
    computerzworld, Aug 2, 2009 IP
  4. That-Guy

    That-Guy Peon

    Messages:
    452
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #4
    This may work the last line is slightly different. Works for me fine :)

    
    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^example.com [NC]
    RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
    
    Code (markup):
     
    That-Guy, Aug 2, 2009 IP