2017-09-04 191 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