Apache Site Goes To Wrong Page If I Manually Enter HTTPS:// in the URL
Neither of these covers the example.com
, and the default site is used, instead:
ServerName www.example.com
ServerAlias *.example.com
If your certificate is a wildcard certificate for example.com
, you could add it to your ServerAlias
:
ServerName www.example.com
ServerAlias example.com *.example.com
It is also possible to avoid using mod_rewrite altogether by adding another VirtualHost *:443
block:
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerName www.example.com
#...
</VirtualHost>
<VirtualHost *:443>
ServerName example.com
ServerAlias *.example.com
Redirect permanent / https://www.example.com/
SSLCertificateFile /etc/letsencrypt/live/www.example.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/www.example.com/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>
</IfModule>