How to Force SSL Connections with a Website

You can force visitors of your website to use SSL connections (HTTPS) if your web server uses Apache for its web services. Most web hosting providers use Apache for their Linux servers. To automatically redirect someone to the SSL (HTTPS) version of your website place the following at the top level of your website directory inside of a file named .htaccess:

RewriteEngine on
RewriteCond %{HTTPS} !^on$ [NC]
RewriteRule . https://%{HTTP_HOST}%{REQUEST_URI} [L]

Alternatively, you can use this instead:

RewriteEngine On
RewriteCond %{SERVER_PORT} !443$
RewriteRule ^(.*)$ https://www.example.com/$1 [L,R]