title: How can I redirect only main page to https and without www?
body: <p>How can I redirect only main page to https and without www?</p>
  
  <pre><code>http://www.mywebsite.com
  http://mywebsite.com
  https://www.mywebsite.com
  </code></pre>
  
  <p>All of URLs above should redirect once to:</p>
  
  <pre><code>https://mywebsite.com
  </code></pre>
  
  <p>Everything inside subdirectories should stay intact</p>
  
  <pre><code>https://mywebsite.com/website-in-progress
  </code></pre>
  
  <p>I am trying various code I have found but I didn't find anything to work all cases. </p>
  
  <p><strong>EDIT</strong>: This seems to be working visually great, the problem is that some URLs have multiple redirects</p>
  
  <pre><code>RewriteEngine On
  
  RewriteCond %{HTTPS} !=on
  RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R=301,L]
  
  RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
  RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
  </code></pre>
  
  <p>The outcome of this is: </p>
  
  <pre><code>- https://mywebsite.com/ - OK
  - https://www.mywebsite.com/ - not desirable, redirects first to http://mywebsite.com and then to https://mywebsite.com
  - http://www.mywebsite.com/ - not desirable, redirects first to https://www.mywebsite.com and then to https://mywebsite.com
  - http://mywebsite.com/ - OK, redirects once to https://mywebsite.com/
  </code></pre>