【问题标题】:Web.config webServer rewrite rules for local and remoteWeb.config webServer 重写本地和远程规则
【发布时间】:2014-07-08 09:48:03
【问题描述】:

我有一个应用程序,我想通过 http 在本地运行并通过 https 远程(在 Azure 上)运行,所以我将它添加到我的 web.config 文件中。

<system.webServer>
    <rewrite>
      <rules>
        <rule name="Redirect to https">
          <match url="(.*)"/>
          <conditions>
            <add input="{HTTPS}"
                 pattern="Off"/>
            <add input="{REQUEST_METHOD}"
                 pattern="^get$|^head$" />
          </conditions>
          <action type="Redirect"
                  url="https://{HTTP_HOST}/{R:1}"/>
        </rule>
      </rules>
    </rewrite>
</system.webServer>

将它部署到 Azure 后,它在远程服务器上运行良好,但是当我在本地运行它时,会发生重新路由,并且我收到 SSL 连接错误,因为我没有或想要本地 ssl 证书。

我已尝试使用以下规则(使用额外的输入测试 localhost)来克服本地问题,但似乎损坏已完成,我尝试过的任何其他方法都无法让我的本地站点再次工作。

<system.webServer>
    <rewrite>
      <rules>
        <rule name="Redirect to https">
          <match url="(.*)"/>
          <conditions>
            <!-- This has been added -->
            <add input="{HTTP_HOST}"
                 pattern="localhost"
                 negate="true"/>

            <add input="{HTTPS}"
                 pattern="Off"/>
            <add input="{REQUEST_METHOD}"
                 pattern="^get$|^head$" />
          </conditions>
          <action type="Redirect"
                  url="https://{HTTP_HOST}/{R:1}"/>
        </rule>
      </rules>
    </rewrite>
</system.webServer>

有人介意让我摆脱痛苦并解释我哪里出错了吗?

【问题讨论】:

    标签: iis azure ssl web-config


    【解决方案1】:

    我现在已经开始工作了!

    我确信我之前的一些尝试应该也能正常工作,但没有意识到我需要清除 Chrome 中的缓存 - 我猜 Chrome 会缓存此类重定向?

    无论如何,我添加了这条规则并删除了缓存,一切都按我的预期工作!

    <rule name="Redirect to http"
              stopProcessing="true">
          <match url=".*" />
          <conditions logicalGrouping="MatchAll"
                      trackAllCaptures="false">
            <add input="{HTTP_HOST}"
                 pattern="localhost" />
          </conditions>
          <action type="None" />
    </rule>
    

    希望其中的一些可能在未来对其他人有所帮助...

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-12-06
      • 1970-01-01
      • 2013-08-19
      • 2017-02-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多