I'm trying to do Virtualhosts on my "playground" VPS.
I need it to redirect 3 or more domains to the main one.
Also it should redirect HTTPS, Lets Encrypt is configured and working well.
In current state, this config works fine, BUT when user goes to HTTPS secsite.com manually (entering HTTPS himself), it redirects to mainsite first and then redirects again back to secsite.com.
<VirtualHost *:80>
ServerName mainsite.com
ServerAlias *.mainsite.com secsite.com *.secsite.com
RewriteRule !https:\/\/mainsite\.com https://mainsite.com%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerName mainsite.com
ServerAlias *.mainsite.com secsite.com *.secsite.com
RewriteRule !https:\/\/mainsite\.com https://mainsite.com%{REQUEST_URI} [END,NE,R=permanent]
ServerAdmin webmaster@localhost
DocumentRoot /var/www/mainsite.com
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
SSLCertificateFile /etc/letsencrypt/live/mainsite.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/mainsite.com/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>
</IfModule>
Any idea how to get this work?