【问题标题】:IIS Rewrite RulesIIS 重写规则
【发布时间】:2018-02-12 19:39:29
【问题描述】:

我发现了两种不同的重写规则来强制 IIS 托管网站使用 HTTPS。我有一个将托管在使用此规则的 Azure 应用服务上的网站。

选项 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. 选项 1 中将 ignoreCase 设置为 false 的原因是什么?
  2. REQUEST_METHOD 输入是否将安全性限制为选项 2 中的 GET 和 HEAD?
  3. appendQueryString="true" 是否将查询字符串保持在重定向状态?
  4. 还有其他不属于其中的选项吗?

【问题讨论】:

    标签: azure iis url-rewrite-module


    【解决方案1】:

    我建议阅读官方文档:

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

    你可以找到它的所有属性解释。

    • ignoreCase – 使用此属性来控制条件的模式匹配是区分大小写还是不区分大小写。

    • appendQueryString – 指定在替换期间是否应保留当前 URL 的查询字符串。默认情况下,如果未指定 AppendQueryString 标志,则假定为 TRUE。这意味着来自原始 URL 的查询字符串将附加到替换的 URL。

    【讨论】:

    • 感谢您的链接。关于 REQUEST_METHOD 条件的作用有什么想法吗?它似乎将重定向限制为 GET 和 HEAD 请求。
    • 是对Http_Method的限制(只有在http_method是get o head时才重定向),我觉得第一种比较好。
    猜你喜欢
    • 1970-01-01
    • 2014-05-01
    • 2014-10-27
    • 1970-01-01
    • 1970-01-01
    • 2011-04-21
    相关资源
    最近更新 更多