Htaccess redirect HTTP & HTTPS non-www to HTTPS www

.htaccessmod-rewriteredirect

How can I redirect my website from all HTTP requests to HTTPS and non-www HTTPS to HTTPS with www?

Example:

Redirect HTTP non-www, HTTP www. & HTTPS non-www:

HTTP://example.com/ && HTTP://www.example.com/ && HTTPS://example.com/

everything to HTTPS with www.:

HTTPS://www.example.com/

Best Answer

# Redirect all "not correct" domain to www with https
# (is not important if comes with or without https):
RewriteCond %{HTTP_HOST} !^www.example.com$ [NC]
RewriteRule ^(.*)$ https://www.example.com/$1 [L,R=301]

# Redirect all non-ssl to ssl.
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://www.example.com/$1 [R,L]

I think this will work with your actual rules.