0

How to redirect all subdomains to the root domain?

It works for non-SSL domains, but doesn't work for SSL domains!?

eg

Works!    
wee.domain.com => https://domain.com
www.domain.com => https://domain.com

Doesn't work! (no redirecting)
https://wee.domain.com => https://domain.com
https://www.domain.com => https://domain.com

vhosts

<VirtualHost *:80>
    ServerName domain.com

    #   force https
    RewriteEngine On
    RewriteCond %{HTTPS}        off
    RewriteRule ^           https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,QSA]

    ...

</VirtualHost>

<VirtualHost *:443>
    ServerName domain.com

    SSLEngine on
    ...

</VirtualHost>

<VirtualHost *:80>
    ServerAlias *.domain.com

    RewriteEngine on
    #   Redirect all subdomains to root
    RewriteRule ^           https://domain.com [L,R=301]

    ...

</VirtualHost>

##########   This vhost is not working   ###############

<VirtualHost *:443>
    ServerAlias *.domain.com

    RewriteEngine on
    #   Redirect all subdomains to root
    RewriteRule ^           https://domain.com [L,R=301]

    SSLEngine on
    ...

</VirtualHost>
clarkk
  • 1,875
  • 7
  • 22
  • 31
  • Is this solution works for your case ? http://serverfault.com/questions/226908/why-do-htaccess-redirects-work-in-http-but-not-with-https – Nabil Bourenane Apr 13 '15 at 13:19

1 Answers1

2

Add AllowOverride FileInfo in the Directory clause as below:

DocumentRoot /var/www/
<Directory /var/www/>
  AllowOverride FileInfo
</Directory>
Nabil Bourenane
  • 755
  • 4
  • 11