I am trying to redirect all traffic to https and all subdomains to main domain and can't get it right. I am using Ubuntu 14.04 with latest apache2.
I set up virtualhost for port 80 to redirect all traffic to https:
<VirtualHost *:80>
ServerName example.com
Redirect permanent / https://example.com/
</VirtualHost>
and setup ssl virtualhost to redirect all subdomains to main domain:
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerAdmin [email protected]
ServerName example.com
ServerAlias *.example.com
DocumentRoot /var/www/example.com/public_html/
ErrorLog /var/www/example.com/logs/error.log
CustomLog /var/www/example.com/logs/access.log combined
Include /etc/letsencrypt/options-ssl-apache.conf
Include /etc/letsencrypt/options-ssl-apache.conf
Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/letsencrypt/live/example.com-0001/cert.pem
SSLCertificateKeyFile /etc/letsencrypt/live/example.com-0001/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateChainFile /etc/letsencrypt/live/example.com-0001/chain.pem
Redirect permanent / https://example.com
</VirtualHost>
</IfModule>
Result is as follows:
WORKING http://example.com to https://example.com
WORKING http://anything.example.com to https://example.com
NOT WORKING https://anything.example.com to https://example.com
Question is: how I redirect ssl subdomain to main domain?
Please tell me what am I doing wrong.
Thanks a lot.
https
, even to redirect or process your "alias," you have to have a valid SSL certificate for whatever domain the client sends. The SSL handshake takes place before anything in the Apache server is processed. In other words, if you are not using a wildcard SSL certificate, the SSL handshake will fail forhttps://anything.example.com
before the Apache configuration file ever has a chance to process the alias.