虚拟主机

虚拟主机

如何将所有子域重定向到根域?

它适用于非 SSL 域,但不适用于 SSL 域!?

例如

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

虚拟主机

<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>

答案1

添加AllowOverride FileInfo目录条款如下:

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

相关内容