簡體   English   中英

Web.config WebServer本地和遠程的重寫規則

[英]Web.config webServer rewrite rules for local and remote

我有一個應用程序,希望通過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>

有人會介意讓我擺脫痛苦,並解釋我要去哪里錯嗎?

我已經開始工作了!

我確信以前的一些嘗試也能奏效,但沒有意識到我需要清除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>

希望其中一些將來可以幫助其他人...

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM