title: Use .htaccess to redirect HTTP to HTTPs
body: <p>I have tried <a href="https://serverfault.com/questions/214512/redirect-change-urls-or-redirect-http-to-https-in-apache-everything-you-ever">this post</a>, and many others (<a href="https://stackoverflow.com/questions/13977851/htaccess-redirect-to-https-www">1</a>, <a href="https://stackoverflow.com/questions/10489895/http-to-https-through-htaccess">2</a>, <a href="https://stackoverflow.com/questions/12999910/https-to-http-redirect-using-htaccess">3</a>, <a href="https://stackoverflow.com/questions/17638611/redirect-all-http-and-https-non-www-urls-to-https-www-xyz-com-via-htaccess">4</a>), but they all give me TOO_MANY_REDIRECTS or error 500. So, here is my issue:</p>
  <p>With my current .htaccess, this is what happens:</p>
  <p><a href="https://www.dukescasino.com/" rel="nofollow noreferrer">https://www.dukescasino.com/</a> - works perfectly</p>
  <p><a href="https://dukescasino.com/" rel="nofollow noreferrer">https://dukescasino.com/</a> - redirects to the above which is great</p>
  <p>The two options below loads fine, but it should be redirecting to the https version:</p>
  <p><a href="http://www.dukescasino.com/" rel="nofollow noreferrer">http://www.dukescasino.com/</a></p>
  <p><a href="http://dukescasino.com/" rel="nofollow noreferrer">http://dukescasino.com/</a></p>
  <p>Here is the current .htaccess:</p>
  <pre><code>&lt;IfModule mod_rewrite.c&gt;
  RewriteEngine On
  RewriteBase /
  
  # BEGIN WordPress
  RewriteRule ^index\.php$ - [L]
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule . /index.php [L]
  &lt;/IfModule&gt;
  </code></pre>
  <p>I don't believe it is relevant, but if so, here is the list of current active plugins:</p>
  <ul>
  <li>Advanced Custom Fields</li>
  <li>All In One SEO Pack</li>
  <li>Bop Search Box Item Type For Nav Menus</li>
  <li>Contact Form 7</li>
  <li>Disable Comments</li>
  <li>Google XML Sitemaps</li>
  <li>Jetpack by WordPress.com</li>
  <li>Search &amp; Filter</li>
  <li>Slider WD</li>
  <li>TablePress</li>
  <li>UpdraftPlus - Backup/Restore</li>
  <li>Wordfence Security</li>
  <li>WPide</li>
  <li>WP Smush</li>
  <li>WP Super Cache</li>
  </ul>
  <p><strong>Tests performed:</strong></p>
  <p><strong>Test A:</strong></p>
  <pre><code>&lt;IfModule mod_rewrite.c&gt;
  RewriteEngine On
  RewriteBase /
  
  RewriteCond %{HTTPS} off
  # First rewrite to HTTPS:
  # Don't put www. here. If it is already there it will be included, if not
  # the subsequent rule will catch it.
  RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
  # Now, rewrite any request to the wrong domain to use www.
  RewriteCond %{HTTP_HOST} !^www\.
  RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
  
  # BEGIN WordPress
  RewriteRule ^index\.php$ - [L]
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule . /index.php [L]
  &lt;/IfModule&gt;
  </code></pre>
  <p><em>Result:</em> ERR_TOO_MANY_REDIRECTS</p>
  <p><strong>Test B:</strong></p>
  <pre><code>&lt;IfModule mod_rewrite.c&gt;
  RewriteEngine On
  RewriteBase /
  
  RewriteCond %{HTTPS} !=on
  RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [R,L]
   
  # BEGIN WordPress
  RewriteRule ^index\.php$ - [L]
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule . /index.php [L]
  &lt;/IfModule&gt;
  </code></pre>
  <p><em>Result:</em> ERR_TOO_MANY_REDIRECTS</p>
  <p><strong>Test C:</strong></p>
  <pre><code>&lt;IfModule mod_rewrite.c&gt;
  RewriteEngine On
  RewriteBase /
  
  RewriteCond %{SERVER_PORT} ^80$
   RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]
   
  # BEGIN WordPress
  RewriteRule ^index\.php$ - [L]
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule . /index.php [L]
  &lt;/IfModule&gt;
  </code></pre>
  <p><em>Result:</em> ERR_TOO_MANY_REDIRECTS</p>
  <p><strong>Test D:</strong></p>
  <pre><code>&lt;IfModule mod_rewrite.c&gt;
  RewriteEngine On
  RewriteBase /
  
  RewriteCond %{HTTPS} off
  RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
  
  # BEGIN WordPress
  RewriteRule ^index\.php$ - [L]
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule . /index.php [L]
  &lt;/IfModule&gt;
  </code></pre>
  <p><em>Result:</em> ERR_TOO_MANY_REDIRECTS</p>
  <p><strong>Test E:</strong></p>
  <pre><code>&lt;IfModule mod_rewrite.c&gt;
  RewriteEngine On
  RewriteBase /
  
  RewriteCond %{HTTP_HOST} !^www\.
  RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI}$1 [R=301,L]
  RewriteCond %{HTTPS} off
  RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI}$1
  
  # BEGIN WordPress
  RewriteRule ^index\.php$ - [L]
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule . /index.php [L]
  &lt;/IfModule&gt;
  </code></pre>
  <p><em>Result:</em> 302 found. Additionally, a 500 Internal Server Error error was encountered while trying to use an ErrorDocument to handle the request.</p>