HTTPS 重定向无效

HTTPS redirect is not working

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

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

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

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

时没有发生重定向

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

无论使用 http 还是 https,您只需要一个重定向规则即可转到您的新域。如果你想在新域中使用https从旧重定向到新,你可以使用这个。

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

如果您想要一对一规则并将 http 重定向到 http,将 https 重定向到 https,那么您可以这样做。

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

这表明您仍然拥有旧域的有效证书。如果您不这样做,它将 不会 https 起作用,并且仅对 http 有效。您将收到证书警告,并且在您越过该错误之前不会发生重定向。