HTTPS重定向无效

时间:2015-03-04 17:15:30

标签: apache mod-rewrite redirect ssl https

这就是我在conf文件中的内容:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^test\.old\.com$ [NC]
RewriteCond %{HTTPS} on
RewriteRule ^(.*)$ https://test-new.com$1 [QSA,R=301,L]

RewriteCond %{HTTP_HOST} ^test\.old\.com$ [NC]
RewriteRule ^(.*)$ http://test-new.com$1 [QSA,R=301,L]

当我转到test.old.com时重定向,但在我尝试https://test.old.com时没有重定向

如何在网址中使用https将https请求重定向到新域?

1 个答案:

答案 0 :(得分:1)

您无需使用http或https,只需要一个重定向规则即可转到新域。如果您想在新域中使用https从旧版重定向到新版,则可以使用此功能。

RewriteCond %{HTTP_HOST} ^test\.old\.com$ [NC]
RewriteRule ^(.*)$ https://test-new.com/$1 [QSA,R=301,L]

如果您想要一对一规则并将http重定向到http并将https重定向到https,那么您可以执行此操作。

RewriteCond %{HTTP_HOST} ^test\.old\.com$ [NC]
RewriteCond %{HTTPS} ^on
RewriteRule ^(.*)$ https://test-new.com/$1 [QSA,R=301,L]
RewriteCond %{HTTP_HOST} ^test\.old\.com$ [NC]
RewriteCond %{HTTPS} !^on
RewriteRule ^(.*)$ http://test-new.com/$1 [QSA,R=301,L]

这表明您仍然拥有旧域的有效证书。如果不这样做, <{1}}仅适用于https。您将收到证书警告,在您继续执行该错误之前不会进行重定向。

相关问题