htaccess rewrite

Discussion in 'Apache' started by NorthSouth, Jun 26, 2010.

  1. #1
    hi
    I've been using this rewrite and it works fine but now I'm using a subdomain so things are getting redirected inappropriately, please advise how to have non www redirect to www., but excluding a specific subdomain

    RewriteEngine on
    RewriteCond %{HTTP_HOST} !^www\.domainname\.com$ [NC]
    RewriteRule ^(.*)$ http://www.domainname.com/$1 [R=301,L]

    Thank you
     
    NorthSouth, Jun 26, 2010 IP
  2. madaboutlinux

    madaboutlinux Member

    Messages:
    250
    Likes Received:
    7
    Best Answers:
    2
    Trophy Points:
    43
    #2
    The following code will redirect the non www request coming to your main website to www of the main website.
    This won't affect the sub-domains.
     
    madaboutlinux, Jun 27, 2010 IP
  3. NorthSouth

    NorthSouth Peon

    Messages:
    43
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks for the suggestion but this results in the following message from http://subdomain. or http://www.

    Firefox has detected that the server is redirecting the request for this address in a way that will never complete.

    or
    Safari can’t open the page.
    Too many redirects occurred trying to open “http://www.domainname.com/”. This might occur if you open a page that is redirected to open another page which then is redirected to open the original page.


    However http://domainname.com works.

    Thanks
     
    NorthSouth, Jun 27, 2010 IP
  4. esupportsnet

    esupportsnet Greenhorn

    Messages:
    34
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    16
    #4
    Try this,

    Options +FollowSymLinks
    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^domain\.com
    RewriteRule ^(.*)$ http://www.domain.com/$1 [L,R=301]
     
    esupportsnet, Jun 29, 2010 IP
  5. NorthSouth

    NorthSouth Peon

    Messages:
    43
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Awesome, this works perfectly, thank you esupportsnet
     
    NorthSouth, Jun 29, 2010 IP