根据传入 IP 地址绕过 web.config 文件中的规则

Bypass a rule in web.config file based on incoming IP address

我已经尝试了 6 个小时的解决方案来解决这个问题,但在堆栈或 Microsoft 的开发博客上都找不到任何内容。我试图强制从所有外部调用 HTTPS 重定向到我的网站,同时在通过内部调用访问网站时仍然转到 HTTP 站点,在这种情况下,通过使用 [=36= 中的 IP 地址 192.168.8.68 ] 浏览器栏。在我们昨天安装了 SSL 证书并实施了以下重定向规则之前,这一切都很好:

<rule name="Redirect to HTTPS" patternSyntax="Wildcard" stopProcessing="true">
    <match url="*" />
    <conditions logicalGrouping="MatchAny">
        <add input="{HTTPS}" pattern="OFF" />
    </conditions>
    <action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" appendQueryString="false" />
</rule>

我想知道的是,如果传入 IP 地址的格式为 192.168.8.*,我将如何绕过它?在正则表达式中添加特定的 iP 会导致网站无法加载 "Too many redirects error"。为了解决这个问题,我已经查看了以下问题列表:

https://forums.iis.net/t/1166994.aspx?Rewrite+Redirection+for+only+external+users

IIS 7.5 redirect certain requests to other server using ip address

https://docs.secureauth.com/display/KBA/Use+URL+Rewrite+for+IP+Restrictions

Two instances of the same Website on IIS with different web.config (two different databases)

您可以使用此规则绕过来自 ip 192.168.8.* 的请求。

<rule name="Redirect to HTTPS" enabled="true" patternSyntax="ECMAScript" stopProcessing="true">
    <match url=".*" />
    <conditions logicalGrouping="MatchAny">
                        <add input="{HTTPS}" pattern="OFF" />
                        <add input="{REMOTE_ADDR}" pattern="192\.168\.8\.[0-9]+" negate="true" />
    </conditions>
    <action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" appendQueryString="false" redirectType="Permanent" />
</rule>