Web.config webServer重写本地和远程规则

时间:2014-07-08 09:48:03

标签: iis azure ssl web-config

我有一个应用程序,我希望通过http和远程(在Azure上)通过https在本地运行,所以我将其添加到我的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>

有人会介意让我摆脱困境并解释我哪里出错吗?

1 个答案:

答案 0 :(得分:3)

我现在已经开始工作了!

我确定我以前的一些尝试应该也能正常运行,但我没有意识到我需要清除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>

希望将来有些可能对其他人有所帮助......

相关问题