title: Redirect to non www is not working for pages in https
body: <p>I am trying to add redirect rules using .htaccess for such goals:</p>
  
  <ol>
  <li>Redirect all http pages to https.</li>
  <li>Redirect all www http and https pages to non www https.</li>
  </ol>
  
  <p>My .htaccess code:</p>
  
  <pre><code>RewriteEngine On
  RewriteCond %{HTTPS} off
  RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
  
  RewriteCond %{HTTPS} on
  RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
  RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
  </code></pre>
  
  <p>Everything is working good except one:</p>
  
  <ul>
  <li>http redirects to https (all pages)</li>
  <li>https www redirects to https non www (main page and subfolders)</li>
  </ul>
  
  <p>But <a href="https://www.example.com/1/page.html" rel="nofollow noreferrer">https://www.example.com/1/page.html</a> does not redirect to <a href="https://example.com/1/page.html" rel="nofollow noreferrer">https://example.com/1/page.html</a> (both pages open)</p>
  
  <p>What is the problem? How to write an .htaccess rule to redirect all the pages to https non www?</p>