2
在Apache 2.4.6中,我想将请求从http://A.org/foo
和https://A.org/foo
重定向到https://B.org/foo
。将http和https请求重定向到新主机
我使用下列指令:
<VirtualHost 1.2.3.4:80>
ServerName B.org
ServerAlias A.org
RewriteEngine on
RewriteCond %{HTTP_HOST} !^B.org$
RewriteRule ^/(.*)$ https://B.org/$1 [R=permanent,L]
</VirtualHost>
<VirtualHost 1.2.3.4:443>
ServerName B.org
ServerAlias A.org
RewriteEngine on
RewriteCond %{SERVER_PORT} ^443(s)
RewriteCond %{HTTP_HOST} !^B.org$
RewriteRule ^/(.*)$ https://B.org/$1 [R=permanent,L]
</VirtualHost>
当我访问http://A.org/foo
,这重定向到https://B.org/foo
(正确的)。
当我访问https://A.org/foo
时,会加载https://B.org/foo
但不会重写URL。所以我从Web浏览器中得到一个SSL证书域不匹配的错误。
第二个VirtualHost
指令有什么问题会阻止URL被重写吗?
注释掉'RewriteCond%{SERVER_PORT}^443(s)'行并在清除浏览器缓存后重新测试。 – anubhava
我得到相同的行为。 –