How can I redirect HTTP to HTTPS using an .htaccess file?

You can automatically redirect visitors to the secured (HTTPS) version of your site to make sure your communications are encrypted by using following in your .htaccess file.

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L]