Non www to www .htaccess

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

  1. #1
    Hey,

    Opened up the .htaccess file on the root of the site and it contained some info for $GET request but I also want to put something for non www pages to redirect to www pages. Basically a 301 redirect from non www. to www.

    So far the .htaccess file contains:

    I normally know how to do this but think something currently in the .htaccess must be affecting this - any ideas guys - what line of code should I use?

    Any help much appreciated.

    Thanks,

    Darrell
     
    dazfree, Jan 23, 2009 IP
  2. pr0t0n

    pr0t0n Well-Known Member

    Messages:
    243
    Likes Received:
    10
    Best Answers:
    10
    Trophy Points:
    128
    #2
    You can add this two lines bellow your rules in .htaccess :

    
    RewriteCond %{HTTP_HOST} !^www\.
    RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
    
    Code (markup):
    or maybe even better, add it after "RewriteEngine On" line, so those two lines could be the first rule(s) that apply.
     
    pr0t0n, Jan 24, 2009 IP
  3. JoelJonathan

    JoelJonathan Peon

    Messages:
    152
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Add this:


    RewriteCond %{HTTP_HOST} !^www.mydomain.com$ [NC]
    RewriteRule ^(.*)$ http://www.mydomain.com/$1 [L,R=301]
    Code (markup):
    right after the:

    RewriteEngine on
    Code (markup):
     
    JoelJonathan, Jan 26, 2009 IP