How do I force SSL on Craft? I've installed a ssl cert on a site and it's working. Now I want to redirect visitors coming in on http over to https

I've put this code and only this code in the htaccess file, but it's causing a redirect loop.

&lt;IfModule mod_rewrite.c&gt;
RewriteEngine On

RewriteCond %{SERVER_PORT} 80 
RewriteRule ^(.*)$ https://www.mysite.com/$1 [R,L]

&lt;/IfModule&gt;


My original htaccess looked like this:

&lt;IfModule mod_rewrite.c&gt;
RewriteEngine On

RewriteCond %{HTTP_HOST} ^mysite.com [NC]
RewriteRule ^(.*)$ https://www.mysite.com/$1 [L,R=301]

# Send would-be 404 requests to Craft
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/(favicon\.ico|apple-touch-icon.*\.png)$ [NC]
RewriteRule (.+) index.php?p=$1 [QSA,L]
&lt;/IfModule&gt;


Could Craft somehow be causing the redirect loop?

In the Craft CP I have the Site URL set to https://www.mysite.com
For reference, this worked:

RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule ^(.*)$ https://%{SERVER_NAME}%{REQUEST_URI} [R,L]