Forcing HTTPs redirection

If you want to automatically route the connection from http to https, add the following lines at the beginning of the .htaccess file in the root directory of the domain

Without the prefix www: 

RewriteEngine On

RewriteCond %{HTTPS} !=on

RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] 

With the www prefix:

RewriteEngine On

RewriteCond %{HTTPS} off

RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

RewriteCond %{HTTP_HOST} !^www\. [NC]

RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]