如何在IIS8.5上自定义重定向http到https

How to customize redirecting http to https on IIS8.5

我需要在外部网络(互联网)上将 http 重定向到 https,但在 192.168.1.100 等本地网络上可以使用 http。我使用了以下配置:

<system.webServer> 
<rewrite> 
<rules> 
<rule name="HTTPS force" enabled="true" stopProcessing="true"> 
<match url="(.*)" /> 
<conditions> 
<add input="{HTTPS}" pattern="^OFF$" /> 
</conditions> 
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="Permanent" /> 
</rule> 
</rules> 
</rewrite> 
</system.webServer>

您可以添加一个附加条件 "host shouldn't match 192.168.1.100"。

你的规则应该是这样的:

<rule name="HTTPS force" enabled="true" stopProcessing="true"> 
    <match url="(.*)" /> 
    <conditions>
        <add input="{HTTPS}" pattern="^OFF$" />
        <add input="{HTTP_HOST}" pattern="^192.168.1.100$" negate="true" /> 
    </conditions> 
    <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="Permanent" /> 
</rule>