title: Redirect to https:// and remove www. in htaccess on WordPress site
body: <p>I want to redirect to <code>https://</code> on my website and remove any <code>www.</code> subdomain in the url using htaccess on my WordPress site, because my security certificate doesn't cover the <code>www</code> subdomain. This is almost working:</p>
  
  <pre><code>&lt;IfModule mod_rewrite.c&gt;
  
  RewriteEngine On
  
  RewriteBase /
  
  RewriteCond %{HTTP_HOST} ^www\.
  RewriteCond http%1://%{HTTP_HOST} ^(https?://)(www\.)?(.+)$
  RewriteRule ^ https://%3%{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;   
  
  # END WordPress
  </code></pre>
  
  <p>This redirects to <code>https://</code> and removes <code>www.</code> from <code>http://</code> urls. However, it doesn't remove the subdomain if the <code>https://</code> is already there, so e.g. <code>http://www.example.com</code> is changed to <code>https://example.com</code>, but <code>https://www.example.com</code> remains unchanged.</p>
  
  <p>What am I doing wrong?</p>