LAMP
.htaccess
Force SSL
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
Force WWW
RewriteEngine on
RewriteCond %{HTTP_HOST} ^hostname.com [NC]
RewriteRule ^(.*)$ https://www.hostname.com/$1 [L,R=301,NC]