Apache2 is not redirecting by default http to https on one of the rules when domain starts with http://www. My domain using certbot.
000-default.conf - disabled
https://domain.com/- loading correctly
https://www.domain.com/ - loading correctly
http://domain.com - redirect correctly
http://www.domain.com - loads Apache2 Ubuntu Default Page
I tried many combinations, please see my current vhost files setup.
My /var/www/html/.htaccess
RewriteEngine on
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^/(.*) https://%{SERVER_NAME}/$1 [NC,R=301,L]
My /etc/apache2/sites-available/my_project.conf
<VirtualHost *:80>
        ServerName domain.com
        ServerAlias www.domain.com
        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/html
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
RewriteEngine on
RewriteCond %{SERVER_NAME} =www.domain.com [OR]
RewriteCond %{SERVER_NAME} =domain.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
My /etc/apache2/sites-available/my_project-le-ssl.conf
<IfModule mod_ssl.c>
<VirtualHost *:443>
        ServerName domain.com
        ServerAlias www.domain.com
        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/html
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
        #django app directory setup
        #django app WSGI setup
Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/letsencrypt/live/www.domain.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/www.domain.com/privkey.pem
</VirtualHost>
</IfModule>
<IfModule mod_ssl.c>
<VirtualHost *:80>
Maybe I am missing something, could you point me in right direction?
