#First rewrite any request to the wrong domain to use the correct one (here www.)
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^/(.*) http://%{HTTP_HOST}:443/$1 [L,R]
#Now, rewrite to HTTPS:
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]