如何在apache中将子域重定向到https主域

时间:2014-12-27 18:15:22

标签: apache .htaccess redirect

我有一些网站example.biz。我将所有http请求重定向到https,但是如何重定向子域(不包括位于不同配置文件中的一个主机)?我需要这样的事情:如果我写bla-bla.example.biz,我必须重定向到example.biz。但如果ololo.bla-bla.example.biz - 错误。所有这些重定向必须是https。尽管如此,我无法将*.example.biz添加到ServerAlias,因为我有另一个网站adm.example.biz。现在,如果我写了any.example.biz之类的东西,我就离开了主页。

example.com的配置:

<VirtualHost *:80>
        ServerAdmin i@example.com
        ServerName example.biz
        ServerAlias www.example.biz
        UseCanonicalName On
        DocumentRoot /var/www/example/webapps
        LogLevel warn
        RewriteEngine On
        RewriteCond %{HTTPS} off
        RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
        ErrorLog ${APACHE_LOG_DIR}/example-error.log
        CustomLog ${APACHE_LOG_DIR}/example-access.log combined
</VirtualHost>

https config:

<IfModule mod_ssl.c>
        <VirtualHost _default_:443>
                ServerAdmin i@example.com
                ServerName example.biz
                ServerAlias www.example.biz
                UseCanonicalName On
                DocumentRoot /var/www/example/webapps/
                LogLevel warn
                ErrorLog ${APACHE_LOG_DIR}/example-error.log
                CustomLog ${APACHE_LOG_DIR}/example-access.log combined

                <Directory />
                        Options FollowSymLinks
                        AllowOverride None
                </Directory>

                <Directory /var/www/rockfutur/webapps/rockfutur/>
                        Options Indexes FollowSymLinks MultiViews
                        AllowOverride All
                        Order allow,deny
                        allow from all
                </Directory>
                SSLEngine on
                SSLCertificateFile      /etc/ssl/certs/example.pem
                SSLCertificateKeyFile /etc/ssl/private/example.key

                <FilesMatch "\.(cgi|shtml|phtml|php)$">
                                SSLOptions +StdEnvVars
                </FilesMatch>
                <Directory /usr/lib/cgi-bin>
                                SSLOptions +StdEnvVars
                </Directory>

                BrowserMatch "MSIE [2-6]" \
                                nokeepalive ssl-unclean-shutdown \
                                downgrade-1.0 force-response-1.0
                # MSIE 7 and newer should be able to use keepalive
                BrowserMatch "MSIE [17-9]" ssl-unclean-shutdown

        </VirtualHost>
</IfModule>

0 个答案:

没有答案