title: Redirecting http=>https (non-www) + www https=> non-www https (no certificate for www)
body: <p>I have seen many articles on rewrites. All good. But none covering this exact situation. So here is my question: hope you can help. Because I cannot get it to work. </p>
  
  <ul>
  <li>we run website on domain.com (non-www)</li>
  <li>we have ssl set up (so https only)</li>
  <li>we have 1 certificate for the non-www version (not www version)</li>
  </ul>
  
  <p>When we execute all four test cases, 3 are OK, 1 not</p>
  
  <ol>
  <li><a href="http://domain.com" rel="nofollow">http://domain.com</a> => <a href="https://domain.com" rel="nofollow">https://domain.com</a> => </li>
  <li><a href="http://www.domain.com" rel="nofollow">http://www.domain.com</a> => <a href="https://domain.com" rel="nofollow">https://domain.com</a> => oK</li>
  <li><a href="https://domain.com" rel="nofollow">https://domain.com</a> => OK</li>
  <li><a href="https://www.domain.com" rel="nofollow">https://www.domain.com</a> => ERROR. Certificate warning not safe</li>
  </ol>
  
  <p><strong>Question</strong>: Now why is number 4 <a href="https://www">https://www</a> giving me this error. I would expect the first rule to pick-up and send us to the non-www version. And how do I fix this?</p>
  
  <p>Appreciate any help ;P Sean</p>
  
  <hr>
  
  <p>This is my currect htaccess</p>
  
  <pre><code>&lt;IfModule mod_rewrite.c&gt;
    RewriteEngine on
    # Redirect www to non-www first 
    # Added based on article http://stackoverflow.com/questions/234723/generic-htaccess-redirect-www-to-non-www
    RewriteCond %{HTTP_HOST} ^www\.(.+) [NC]
    RewriteRule ^(.*) https://%1/$1 [R=301,NE,L]
  
    # Then redirect http to https (if necessary)
    RewriteCond %{HTTPS} !=on
    RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R=301,L]
  &lt;/IfModule&gt;
  </code></pre>