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@example.com 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:
Question is: how I redirect ssl subdomain to main domain?
Please tell me what am I doing wrong.
Thanks a lot.