RewriteEngine on
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [NC,R=301,L]
RewriteEngine On
RewriteCond %{HTTPS} !on
RewriteCond %{HTTP_HOST} ^(?>www\.|)(domain\.com)$ [NC]
RewriteRule ^(.*)$ https://www.%1/$1 [R=301,L]
RewriteCond %{HTTPS} !on
RewriteCond %{HTTP_HOST} ^(?>www\.|)(.+\.domain\.com)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]