.htaccess htaccess重定向,但存在https问题

.htaccess htaccess重定向,但存在https问题,.htaccess,.htaccess,我需要重定向 到 我是用电脑做的 RewriteEngine On RewriteCond %{HTTP_HOST} ^(?:www\.)?example\.com$ [NC] RewriteRule ^test/?$ https://user.example.com/test [NC,R=301,L] 现在我的问题是,如果我加载user.example.com/test或 我得到user.example.com/test,但我需要得到 如何修改或添加规则以执行此操作?您需要在规则中检查

我需要重定向

我是用电脑做的

RewriteEngine On

RewriteCond %{HTTP_HOST} ^(?:www\.)?example\.com$ [NC]
RewriteRule ^test/?$ https://user.example.com/test [NC,R=301,L]
现在我的问题是,如果我加载user.example.com/test或

我得到user.example.com/test,但我需要得到


如何修改或添加规则以执行此操作?

您需要在规则中检查https

RewriteEngine On
RewriteCond %{HTTPS} !^on [OR]
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$ [NC]
RewriteRule ^test/?$ https://user.example.com/test [NC,R=301,L]

令人惊叹的!成功了。谢谢我有更多的规则要添加,它不会重定向到from example.com/test,如果您也能将该规则添加到existing@Peter它已经涵盖了这些场景,我也进行了测试。清除缓存。另外,不要忘记接受答案,因为它修复了原始问题。它不会从example.com/test和http:example.com/test重定向到https:user.example.com/test。很抱歉,我没有足够的声誉来投票支持你的答案这两个答案是相同的
example.com/test
http://example.com/test
,只是如果您使用的是chrome浏览器,它会隐藏http://文件,因此该部分是不相关的。但它确实有效。我对答案做了一个小改动。在另一个浏览器中尝试,并/或清除缓存。你可以测试一下