2015-06-24 29 views
3

我碰到這條規則來:

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

什麼是ON或OFF模式,這是什麼模式匹配?

+1

爲什麼'模式= 「^ $ OFF」'而不僅僅是'模式= 「關」'? 「{https}」可以返回或打開。那麼爲什麼正則表達式邊界? –

+0

@RoyiNamir非常好的問題。你有答案嗎? –

回答

6

OFF模式確保規則只有在請求通過http進入時才執行,否則可能會以無限循環結束。

因此添加一個條件,指出{HTTPS}關閉。

所述^ =(串的開始,或「負」,如果在一定範圍的開始)

的$ =(字符串的末尾)

雖然額外的開始/停止字符似乎是多餘的了爲此

Here is a blog that discusses inbound rules

+0

非常感謝您的回答 –