首先,我要说的是,经过几个小时的谷歌搜索,我找不到获得所需结果的方法。 问题是:
- 我的网站有 2 个域,例如:(foo.com) 和 (bar.com)
- 我需要将 foo.com 域重定向到 HTTPS
- 我需要 bar.com 保持在其 HTTP 上并且不重定向到 HTTPS
我尝试了很多规则,但没有一个能奏效。例如:
<rule name="Force HTTPS" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll">
<add input="{HTTPS}" pattern="off" ignoreCase="true" />
<add input="{REQUEST_URI}" negate="true" pattern="^(www.)?bar.com$$" ignoreCase="true" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}" appendQueryString="true" redirectType="Permanent" />
</rule>
最佳答案
这应该将 foo.com 重定向到 HTTPS:
<rule name="Add WWW prefix to foo.com and use HTTPS" stopProcessing="true">
<match url="(.*)" ignoreCase="true" />
<conditions>
<add input="{HTTP_HOST}" pattern="^foo\.com" />
</conditions>
<action type="Redirect" url="https://www.foo.com/{R:1}" redirectType="Permanent" />
</rule>
对于 bar.com:
<rule name="Force NonHTTPS" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="on" />
</conditions>
<action type="Redirect" url="http://{HTTP_HOST}/{REQUEST_URI}" />
</rule>
查看第一条规则中的 stopProcessing
属性。当 foo.com 匹配时,它应该停止处理下一个规则。这将不允许触发“强制非 HTTPS”规则。
关于ssl - URL Rewrite Force to https 除了一个域,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50777136/