这是重写规则的碎片
<rules>
<rule name="HTTP to HTTPS redirect" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="off" ignoreCase="true" />
</conditions>
<action type="Redirect" url="https://www.example.com/TEST_SITE/{R:1}"
redirectType="Permanent" />
</rule>
</rules>
我的目的是测试重定向http到https是否适用于我的测试网站,但是,它将是一个无限循环,代码为301(永久移动)
如果我将url =“https://www.example.com/TEST_SITE/{R:1}更改为url =”{HTTP_HOST} / {R:1}“,会工作,不再循环。但是我没有将我重定向到https://www.example.com/TEST_SITE/,而是将我重定向到https://www.example.com/(prod环境)。
有什么想法来解决这个问题?感谢
答案 0 :(得分:0)
我的愚蠢我昨天没有想到这一点...添加您的域名/ HTTP_HOST作为输入条件。
这来自我网站的一个真实例子:
<!-- redirect HTTP naar HTTPS for WordPress https://www.saotn.org/ssl-wordpress-move-wordpress-site-https-definitive-guide/ -->
<!-- see https://www.saotn.org/redirect-http-to-https-on-iis/ and
https://www.saotn.org/iis-url-rewrite-redirect-http-to-https/ for more
information -->
<rule name="example.com http to https" stopProcessing="true">
<match url="(.*)" ignoreCase="true" />
<conditions logicalGrouping="MatchAll">
<add input="{HTTP_HOST}" pattern="^(www.)?example\.com$" />
<add input="{HTTPS}" pattern="off" />
<add input="{URL}" pattern="(.*)" />
</conditions>
<action type="Redirect" url="https://www.example.com/{R:1}" redirectType="Permanent" />
</rule>
TEST_SITE
{URL}
应该采用{R:1}
中的df2 = df
输入模式。
答案 1 :(得分:0)
请尝试
<rule name="HTTP To HTTPS" stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{HTTPS}" pattern="OFF" />
<add input="{HTTP_HOST}" pattern="^(([^\.]+)\.)?example.com$" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:0}" />
</rule>