I have tried to configure a non-www website on Ubuntu 18.04 with Apache 2.4 and I've managed to make things work, my https://example.me works fine. But, www.example.me subdomain is also active (because I've added ServerAlias). The https://www.example.me opens as well and shows no certificate which makes me confused - shouldn't it redirect to https://example.com ? What is a good practice here - should I have both www and non-www subdomains and a separate conf file for each? Should I use only one of them with permanent redirection? Why is redirection not working here, do I need some other directive?
Kind regards.
<VirtualHost *:443>
SSLEngine on
SSLCertificateFile /etc/apache2/ssl/mysite.me.crt
SSLCertificateKeyFile /etc/apache2/ssl/mysite.me.key
SSLCertificateChainFile /etc/apache2/ssl/mysite.me.crt
DocumentRoot /var/www/html
ServerName https://example.me
ServerAlias www.example.me
UseCanonicalName Off
ProxyPreserveHost On
ProxyRequests On
ProxyVia On
#ErrorLog /var/log/httpd/tomcat.error.log
#CustomLog /var/log/httpd/tomcat.log combined
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
Include /etc/apache2/sites-available/redirect.conf
ProxyPass / ajp://localhost:8009/
ProxyPassReverse / ajp://localhost:8009/
</VirtualHost>
<VirtualHost *:80>
ServerAdmin webmaster@mexample.me
ServerName example.me
DocumentRoot /var/www/html
UseCanonicalName Off
Redirect permanent "/" "https://example.me/"
ProxyPreserveHost On
ProxyRequests On
ProxyVia On
#ErrorLog /var/log/httpd/tomcat.error.log
#CustomLog /var/log/httpd/tomcat.log combined
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
Include /etc/apache2/sites-available/redirect.conf
ProxyPass / ajp://localhost:8009/
ProxyPassReverse / ajp://localhost:8009/
#ProxyPass / http://localhost:8080/
#ProxyPassReverse / http://localhost:8080/
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>