Asp.net

IIS url 重寫角色,除了一些 url

  • November 10, 2012

我在 URL 重寫中得到了這條規則,它使用 HTTP 到 HTTPS 重寫對站點的每個請求

<rule name="Force HTTPS" stopProcessing="true">
                   <match url="(.*)" />
                   <conditions>
                       <add input="{HTTPS}" pattern="off" ignoreCase="true" />
                   </conditions>
                   <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" appendQueryString="true" redirectType="Permanent" />
               </rule>

我需要這個角色的另一個規則或例外來重寫或重定向特定的 url 到 HTTP。

那可能嗎?

您可以將不想執行重定向到 HTTPS 的異常添加為額外條件(不等於該 URL),如下所示:

<rule name="Force HTTPS" stopProcessing="true">
   <match url="(.*)" />
   <conditions logicalGrouping="MatchAll">
       <add input="{HTTPS}" pattern="off" ignoreCase="true" />
       <add input="{REQUEST_URI}" negate="true" pattern="^/noredirect/forthis/page\.aspx$" ignoreCase="true" />
       <add input="{REQUEST_URI}" negate="true" pattern="^/noredirect/forthis/page-as-well\.aspx$" ignoreCase="true" />
       <add input="{REQUEST_URI}" negate="true" pattern="^/noredirect/forthis/page-as-well-too\.aspx$" ignoreCase="true" />
   </conditions>
   <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" appendQueryString="true" redirectType="Permanent" />
</rule>

引用自:https://stackoverflow.com/questions/13320614