2017-09-04 157 views
0

我發現了兩個不同的重寫規則來爲IIS託管的網站強制使用HTTPS。我有一個網站將託管在Azure應用服務上,該服務將使用此規則。IIS重寫規則

選項1:

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

選項2:

<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}" redirectType="Permanent"/> 
    </rule> 
    </rules> 
</rewrite> 

問題:

  1. 時哪些IGNORECASE的原因設置爲false選項1?
  2. REQUEST_METHOD輸入是否將選項2中的安全性限制爲GET和HEAD?
  3. appendQueryString =「true」是否使查詢字符串保持重定向?
  4. 是否有任何其他選項可以考慮不屬於這兩者之一?

回答

0

我建議閱讀官方文檔:

https://docs.microsoft.com/en-us/iis/extensions/url-rewrite-module/url-rewrite-module-configuration-reference

你可以找到它的所有屬性解釋。

  • ignoreCase - 使用此屬性來控制條件的模式匹配是區分大小寫還是不區分大小寫。

  • appendQueryString - 指定在替換過程中是否應保留當前URL中的查詢字符串。默認情況下,如果未指定AppendQueryString標誌,則假定它爲TRUE。這意味着來自原始URL的查詢字符串會附加到替代的URL。

+0

感謝您的鏈接。對REQUEST_METHOD條件的作用有什麼想法?它似乎限制了重定向到GET和HEAD請求。 – Josh

+0

是Http_Method的限制(只有在http_method爲get頭時重定向),我認爲第一個選項更好。 – aloji