title: https://www redirect on single domain certificate
body: <p>If I have a SSL certificate for </p>
  
  <pre><code>https://www.example.com 
  </code></pre>
  
  <p>but not for</p>
  
  <pre><code>https://example.com
  </code></pre>
  
  <p>I found <a href="https://stackoverflow.com/a/19509934/2311074">here</a> that I should use </p>
  
  <pre><code>#First rewrite any request to the wrong domain to use the correct one (here www.)
  RewriteCond %{HTTP_HOST} !^www\.
  RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
  
  #Now, rewrite to HTTPS:
  RewriteCond %{HTTPS} off
  RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
  </code></pre>
  
  <p>for correct redirecting. This seems to work, except for one case:</p>
  
  <p>If I enter <code>https://example.com</code> then this won't get redirected to <code>https://www.example.com</code>. Instead I get this:</p>
  
  <p><a href="https://i.stack.imgur.com/iJlHi.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/iJlHi.png" alt="enter image description here"></a></p>
  
  <p>Is this fixable without buying a SSL certificate for <code>https://example.com</code>?</p>