我在同时运行这两条规则时遇到了问题,我的配置文件如下
<VirtualHost *:80>
ServerName mytest.domain.com
ServerAlias www.mytest.domain.com mytest2.domain.com www.mytest2.domain.com
RewriteEngine on
RewriteRule ^ https://mytest.domain.com%{REQUEST_URI} [R=301,L]
</VirtualHost>
<VirtualHost *:443>
ServerName redirects.for.mytest.domain.com
ServerAlias www.mytest.domain.com mytest2.domain.com www.mytest2.domain.com
RewriteEngine On
RewriteRule ^/(.*) https://mytest.domain.com/$1 [L,R]
</VirtualHost>
<VirtualHost *:443>
ServerName mytest.domain.com
DocumentRoot /var/www/mytest/
SSLEngine on
SSLCertificateFile my.crt
SSLCertificateChainFile my.chain
SSLCertificateKeyFile my.key
</VirtualHost>
我想要实现的目标:
- HTTP 中的所有内容都会重定向到 HTTPS
- 所有别名和 www 域名必须重定向到其“主要”版本
我可以做其中一个,但混合两者会产生无限的重定向循环,正确的方法是什么?