Need to modify my htaccess to redirect non www. to www.

Discussion in 'Apache' started by tyankee, Mar 18, 2013.

  1. #1
    i want to put in my htaccess file a redirect from non www inquiries to www. for my website..

    for example, redirect all domain.com to www.domain.com

    i have coding that will do that but there is already existing coding in my htaccess that i don't want to mess up. coding for zen cart?? and for ceon_uri_mapping.. here is the coding already in there:

    ## BEGIN CEON URI MAPPING REWRITE RULE

    RewriteEngine On

    # Don't rewrite any URIs ending with a file extension (ending with .[xxxxx])
    RewriteCond %{REQUEST_URI} !\.[a-zA-Z]{2,5}$ [OR]
    RewriteCond %{REQUEST_URI} \.(html)$ [NC]
    # Don't rewrite any URIs for some, popular specific file format extensions,
    # which are not covered by main file extension condition above
    RewriteCond %{REQUEST_URI} !\.(mp3|mp4|h264)$ [NC]
    # Don't rewrite any URIs for some specific file format extensions,
    # which are not covered by main file extension condition above
    # Uncomment the following line to apply this condition! (Remove the # at the start of the next line)
    #RewriteCond %{REQUEST_URI} !\.(3gp|3g2|h261|h263|mj2|mjp2|mp4v|mpg4|m1v|m2v|m4u|f4v|m4v|3dml)$ [NC]
    # Don't rewrite admin directory
    RewriteCond %{REQUEST_URI} !^/adminhiddenxxxxxx [NC]
    # Don't rewrite editors directory
    RewriteCond %{REQUEST_URI} !^/editors/ [NC]
    # Don't rewrite logs directory
    RewriteCond %{REQUEST_URI} !^/logs/ [NC]
    # Don't rewrite catalog directory
    RewriteCond %{REQUEST_URI} !^/catalog/ [NC]
    # Don't rewrite tempEP directory
    RewriteCond %{REQUEST_URI} !^/tempEP/ [NC]
    # Don't rewrite mobile
    RewriteCond %{REQUEST_URI} !^/m/ [NC]
    # Handle all other URIs using Zen Cart (its index.php)
    RewriteRule .* index.php [QSA,L]

    ## END CEON URI MAPPING REWRITE RULE


    since i know VERY LITTLE about htaccess coding, can someone please help me here.. btw, the admin directory is of course not real..
     
    tyankee, Mar 18, 2013 IP
  2. D3Tek

    D3Tek Active Member

    Messages:
    164
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    50
    #2
    Quite a simple request, Add this under "RewriteEngine On"

    
     
    RewriteCond %{HTTP_HOST} !^www\.
    RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
    
    Code (markup):
     
    D3Tek, Mar 18, 2013 IP
  3. tyankee

    tyankee Well-Known Member

    Messages:
    1,023
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    150
    #3

    and it won't affect the rewrites following it??
     
    tyankee, Mar 18, 2013 IP
  4. Endurint

    Endurint Peon

    Messages:
    11
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    1
    #4
    What D3Tek posted is exactly right, and no, it will not affect subsequent rewrites. The REQUEST_URI is independent of the HTTP_HOST.
     
    Endurint, Mar 19, 2013 IP
  5. tyankee

    tyankee Well-Known Member

    Messages:
    1,023
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    150
    #5
    why in the world was this flagged as being in the wrong category??? sometimes the geek moderators in here have to chill out a bit and realize we don't all speak geek.. to me this was a programming issue.. how in the world was i supposed to know it had to do with Apache?? :rolleyes:
     
    tyankee, Mar 20, 2013 IP