title: Redirect http traffic to https using .htaccess
body: <p>I'm trying to redirect all http traffic to https. I've not installed and SSL certificate on my server and is using the cloudflare flexible SSL option.</p>
  
  <p>The following code works file </p>
  
  <pre><code>  RewriteEngine on
    RewriteCond %{HTTP_HOST} ^www\.(.*)
    RewriteRule ^.*$ https://%1/$1 [R=301,L]
  </code></pre>
  
  <p>But this redirects <a href="http://www.example.com" rel="nofollow">http://www.example.com</a> to <a href="https://example.com" rel="nofollow">https://example.com</a></p>
  
  <p>However when I add this</p>
  
  <pre><code>RewriteCond %{HTTP_HOST} ^(.*)
  RewriteRule ^(.*)$ http://example.com/$1 [R=301,L]
  </code></pre>
  
  <p>to redirect all non www urls, like <a href="http://example.com" rel="nofollow">http://example.com</a> to <a href="https://example.com" rel="nofollow">https://example.com</a></p>
  
  <p>The site doesn't load and gives me an error saying <strong>Too many redirects</strong> on the browser. How can I fix this and redirect all my http traffic to https://?</p>
  
  <p>Thanks</p>