I've an apache running under AWS Elastic beanstalk. I've got several different domains and I want all of them to end in a specific domain name, in HTTPS.
The redirection from other domains e.g. https://domain1.com to https://maindomain.com returns a SSL certificate error.
In apache, I've two virtual host config, one for the *:80, and one for *:443. Both are set for the maindomain.com. They were created with certbot.
What should be the best practice to have this working for all other domains?
I guess I need to setup a VirtualHost per domain but how shall it be configured in order to have it working with redirections?
Obviously, the following sample doesn't work as it returns a SSL error:
<IfModule mod_ssl.c>
<VirtualHost domain1.com:443>
ServerName domain1.com
RedirectPermanent / https://maindomain.com/
</VirtualHost>
</IfModule>
Here is the default Virtualhost *:80 config
<VirtualHost *:80>
#ServerName maindomain.com
DocumentRoot /var/www/html
<Directory /var/www/html>
Options -Indexes +FollowSymLinks +MultiViews
AllowOverride All
Require all granted
</Directory>
RewriteEngine on
RewriteCond %{SERVER_NAME} =maindomain.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
Here is the default Virtualhost *:443 config
<IfModule mod_ssl.c>
<VirtualHost *:443>
#ServerName maindomain.com
DocumentRoot /var/www/html
<Directory /var/www/html>
Options -Indexes +FollowSymLinks +MultiViews
AllowOverride All
Require all granted
</Directory>
ServerName maindomain.com
SSLCertificateFile /etc/letsencrypt/live/maindomain.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/maindomain.com/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>
</IfModule>
Your help will be very much appreciated.
D