Your htaccess shoud look like this:
RewriteCond %{HTTP_HOST} !^www.example.com
RewriteRule ^(.*)$ https://www.example.com/$1 [R=permanent,L]
RewriteCond %{HTTPS} !=on
RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L]
Configuration might need to be changed according to how your network is setup, for example if you have a load-balancer in front of your apache or according to the apache version you're running.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…