写法1:

RewriteEngine on 
RewriteBase / 
RewriteCond %{SERVER_PORT} !^443$ 
RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [L,R]

写法2:

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteCond %{HTTP:X-Forwarded-Proto} =http
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

写法3:

RewriteCond %{HTTPS} off
RewriteCond %{HTTP:X-Forwarded-Proto} =http
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]