簡體   English   中英

IIS URL重寫https規則忽略localhost

[英]IIS URL Rewrite https rule ignoring localhost

我正在嘗試編寫URL重寫規則來強制HTTPS連接。 這應該總是發生,除非請求使用localhost(例如http://localhost/mysite )。

規則配置如下:

 <rule name="Redirect to https" enabled="true" stopProcessing="true">
      <match url="(.*)" negate="false" />
      <conditions trackAllCaptures="false">
           <add input="{HTTPS}" pattern="^OFF$" />
           <add input="{URL}" pattern="localhost" negate="true" />
      </conditions>
      <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" />
 </rule>

我也嘗試使用^ localhost和^ localhost /(.*)作為URL條件的模式,沒有任何幫助。 有誰知道為什么這不起作用,這個問題的解決方案應該是什么?

你的代碼應該是這樣的

<rule name="Redirect to https" enabled="true" stopProcessing="true">
   <match url="(.*)" />
   <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
      <add input="{HTTPS}" pattern="off" />
      <add input="{HTTP_HOST}" pattern="localhost" negate="true" />
   </conditions>
   <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" />
</rule>

暫無
暫無

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

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