.htaccesssslhttpsmultiple-sites

multiple urls hosted only one needs https


I have several sites on one server but one the urls needs to be https.

for examples sake: http://www.example1.com/ https://www.example2.com/

i've been using htaccess to force https but it does it to ALL the urls essentially breaking all except that one URL i have a SSL cert for.

how can i force https on that one site?


Solution

  • You can use a double-condition in your htaccess:
    - condition 1: check for www.example2.com only
    - condition 2: check for http requests only

    RewriteCond %{HTTP_HOST} ^www\.example2\.com$ [NC]
    RewriteCond %{HTTPS} =off
    RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
    

    This way, every http url from www.example2.com will go to https equivalent