title: Rewrite www to non-www fails on https www when SSL Cert is non-www
body: <p>I've tried to first rewrite www to non-www for both http and https.
  Works for http requests, but for https requests, the browser shows 'connection is not private' when www is present.</p>
  
  <p>My SSL certificate is assigned to non-www. I'm wondering if there's a way to redirect the https www to non-www ? So far I've tried different examples without success:</p>
  
  <pre><code>RewriteEngine On
  
  RewriteCond %{HTTPS} off
  RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
  RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
  
  RewriteCond %{HTTPS} on
  RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
  RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
  </code></pre>
  
  <p>The following error message is displayed in the browser (when <code>https://www.example.com</code>):</p>
  
  <blockquote>
    <p>Your connection is not private</p>
    
    <p>This server could not prove that it is <code>www.example.com</code>; its security
    certificate is from foobar.com. This may be caused by a
    misconfiguration or an attacker intercepting your connection.</p>
  </blockquote>
  
  <p>So far I think it's not possible unless I have the SSL certificate for <code>www.example.com</code> otherwise the connection will never happen and the server won't send a redirection response.</p>