Problem in RewriteRule cannot convert non www to www in https

Discussion in 'Apache' started by ayyappansan, Sep 21, 2009.

  1. #1
    I have looked everywhere for .htaccess code to forward all inbound ssl traffic to my site from non-www to www. Example https://example.com to https://www.example.com.

    My ssl cert is installed on www and all other requests to the main domain cause a browser error. I already have this working for non-ssl urls using .htaccess. Can someone please provide the proper code for ssl as well?

    RewriteEngine On

    rewriteCond %{HTTP_HOST} !^www.example.com$

    rewriteCond %{SERVER_PORT}s ^(443(s)¦[0-9]+s)$

    rewriteRule (.*) http%2://www.example.com/$1 [R=301,L]
     
    ayyappansan, Sep 21, 2009 IP
  2. chadsmith

    chadsmith Peon

    Messages:
    82
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Try:

    RewriteCond %{HTTPS} =on
    RewriteCond %{HTTP_HOST} !^www\.example\.com$
    RewriteRule ^(.*) https://www.example.com/$1 [R=301,L]
    Code (markup):
     
    chadsmith, Sep 24, 2009 IP