Redirect to www with SSL

  • Hello,


    I've one domain with a SSL-Certificate (only for http://www.example.com).
    I want that if you type example.com that you'll redirected to https://www.example.com


    In Chrome it works out of the box. But, for example, Firefox don't redirect to www but only to https.


    I tried to add this rule in .htaccess and in the apache vhosts file, but both didn't work

    Code
    1. RewriteEngine On
    2. RewriteBase /
    3. RewriteCond %{HTTP_HOST} !^www\. [NC]
    4. RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
    5. RewriteCond %{SERVER_PORT} !^443$
    6. RewriteRule (.*) https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]

    Thanks in advance for your help!

  • This works fine for me (Chrome + FF + Edge):


    Code
    1. RewriteEngine On
    2. RewriteCond %{HTTP_HOST} !^www\. [NC]
    3. RewriteRule ^(.*) http://www.%{SERVER_NAME}%{REQUEST_URI} [L,R=301]
    4. #here we dont use www as non www was already redirected to www.
    5. RewriteCond %{HTTPS} off
    6. RewriteRule ^(.*) https://%{SERVER_NAME}%{REQUEST_URI} [L,R=301]