title: .htaccess redirect both http:// with and without www and https://www to https:// non-www
body: <p>I'm looking to redirect all of:</p>
  
  <pre><code>http://
  http://www.
  https://www.
  
  to https://
  </code></pre>
  
  <p>This may have been answered here before, but having gone through the questions that seem relevant they are all not quite what I'm after, and everything I've tried resulted in a redirect loop or not working as hoped.</p>
  
  <p>For example:</p>
  
  <pre><code>RewriteCond %{HTTPS} off
  RewriteCond %{HTTP_HOST} ^www.example.com
  RewriteRule ^(.*)$ https://example.com/$1 [R=301,L]
  
  RewriteCond %{HTTPS_HOST} ^example.com
  RewriteRule ^(.*)$ https://example.com/$1 [R=301,L]
  </code></pre>
  
  <p>Thanks in advance for your help.</p>