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>

marked as duplicate by Jenny D, Sven Apr 14 '15 at 15:31

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

2

Add AllowOverride FileInfo in the Directory clause as below:

DocumentRoot /var/www/
<Directory /var/www/>
  AllowOverride FileInfo
</Directory>

Not the answer you're looking for? Browse other questions tagged or ask your own question.