我正在尝试将所有http流量重定向到https
所以我希望这3个场景成立:
1- http://domain.com -> https://www.domain.com
2- http://www.domain.com -> https://www.domain.com
3- https://domain.com -> https://www.domain.com
我设法让前两个工作,但最后一个工作不起作用。我怎样才能做到这一点?
下面是我的vhost配置。
<virtualhost *:80>
RailsEnv production
ServerName www.domain.com
ServerAlias *.domain.* domain.* domain.com
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_METHOD} ^TRACE
RewriteRule .* - [F]
RewriteCond %{REQUEST_METHOD} ^TRACK
RewriteRule .* - [F]
#redirect all port 80 traffic to 443
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^/?(.*) https://www.domain.com/$1 [L,R]
</IfModule>
<directory /data/project/current/public>
AllowOverride all
Options -MultiViews
</directory>
</virtualhost>
<virtualhost *:443>
RailsEnv production
ServerName www.domain.com
ServerAlias *.domain.* domain.* domain.com
SSLEngine on
SSLCertificateFile /root/cert.crt
SSLCertificateKeyFile /root/cert.key
SSLCertificateChainFile /root/certCA.crt
DocumentRoot /data/project/current/public
<directory /data/project/current/public>
AllowOverride all
Options -MultiViews
</directory>
</virtualhost>