【问题标题】:Prevent subdomain from redirecting to HTTPS防止子域重定向到 HTTPS
【发布时间】:2018-07-14 08:06:14
【问题描述】:

当应用生产转换时,我的web.config 中有以下重写规则。

<system.webServer> <rewrite xdt:Transform="Insert"> <rules> <rule name="Redirect-HTTP-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}" redirectType="Found" appendQueryString="true" /> </rule> </rules> </rewrite> </system.webServer>

当我将带有暂存转换的单独网站部署到同一个 IIS 实例时,此规则不会添加到我的 web.config。然而,staging.example.com 的流量仍然受到规则的约束。

好像生产规则还在追赶它?

制作网址:example.com

暂存网址:staging.example.com

我怎样才能让这条规则不那么贪婪,所以它不会重定向暂存流量。

【问题讨论】:

    标签: asp.net iis url-rewriting iis-7 iis-8


    【解决方案1】:

    您可以在规则中添加其他条件以忽略 staging.example.com:

    <rule name="Redirect-HTTP-TO-HTTPS" patternSyntax="Wildcard" stopProcessing="true">
      <match url="*" />
      <conditions logicalGrouping="MatchAll">
        <add input="{HTTPS}" pattern="off" />
        <add input="{HTTP_HOST}" pattern="^staging\.example\.com$" negate="true" />
      </conditions>
      <action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" redirectType="Found" appendQueryString="true" />
    </rule>
    

    请记住,浏览器通常会缓存 301 重定向。应用此规则后,请清除浏览器缓存或使用隐身模式

    【讨论】:

    • 谢谢!当我添加此条件时,它会将两个站点都放入重定向循环 - 有什么想法吗?
    • 您确定将MatchAll 用于logicalGrouping 吗?
    • 啊,你是对的,我有MatchAny!非常感谢您的帮助!
    猜你喜欢
    • 2014-03-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-06-07
    • 1970-01-01
    • 2016-01-30
    • 1970-01-01
    • 2018-06-02
    相关资源
    最近更新 更多