Forum Moderators: phranque
# if the requested protocol is not HTTPS or
# if the provided Host header value (if any) is not exactly the canonical hostname (or null)
# externally redirect any such noncanonical protocol or hostname requests using a 301 status code to the same requested path (and possibly query string) on the canonical protocol and hostname
RewriteCond %{HTTPS} !on [OR]
RewriteCond %{HTTP_HOST} !^(www\.example\.com)?$
RewriteRule (.*) https://www.example.com/$1 [R=301,L] RewriteRule (.*) https://www.example.com/$1? [R=301,L]