title: redirect https non-www to www
body: <p>I want to redirect:</p>
  <blockquote>
  <p><strong><a href="https://example.com" rel="nofollow noreferrer">https://example.com</a> =&gt; <a href="https://www.example.com" rel="nofollow noreferrer">https://www.example.com</a> [not working]</strong></p>
  <p><strong><a href="http://example.com" rel="nofollow noreferrer">http://example.com</a> =&gt; <a href="https://www.example.com" rel="nofollow noreferrer">https://www.example.com</a> [not working]</strong></p>
  <p>www.example.com =&gt; <a href="https://www.example.com" rel="nofollow noreferrer">https://www.example.com</a> [working]</p>
  <p>example.com =&gt; <a href="https://www.example.com" rel="nofollow noreferrer">https://www.example.com</a> [working]</p>
  </blockquote>
  <p><strong>.htaccess</strong></p>
  <pre><code>RewriteEngine On
  RewriteCond %{HTTPS} off [OR]
  RewriteCond %{HTTP_HOST} !^www\. [NC]
  RewriteCond %{HTTP_HOST} ^(.*)$  [NC]
  RewriteRule (.*) https://www.example.com/$1 [R=301,L]
  </code></pre>
  <p><strong>Virtualhost</strong></p>
  <pre><code>&lt;VirtualHost *:80&gt;
      ServerName example.com
      ServerAlias www.example.com
      DocumentRoot /var/www/test/public_html
      ErrorLog /var/www/test/error.log
      CustomLog ${APACHE_LOG_DIR}/access.log combined
  &lt;/VirtualHost&gt;
  &lt;VirtualHost _default_:443&gt;
      ServerName example.com
      ServerAlias www.example.com
      DocumentRoot /var/www/test/public_html
      ErrorLog /var/www/test/error.log
      SSLEngine on
      SSLCertificateKeyFile /etc/apache2/ssl/test.key
      SSLCertificateFile /etc/apache2/ssl/test.crt
  &lt;/VirtualHost&gt;
  </code></pre>