【问题标题】:IIS URL rewrite based on accept headers and request type基于接受标头和请求类型的 IIS URL 重写
【发布时间】:2015-11-18 14:22:09
【问题描述】:

我是否可以根据 Accept-headers 和请求类型使用 IIS 重写 URL。

我需要 IIS 将所有 URL 重写为 index.html(一个有状态的 js 应用程序),以满足以下条件:

  1. 请求是 GET 请求
  2. 来自客户端的接受标头包括:“text/html”
  3. 不是直接文件请求。请求的路径不包含 . (点)字符

我认为它与 Node 模块相同:https://github.com/bripkens/connect-history-api-fallback

【问题讨论】:

    标签: iis url-rewriting


    【解决方案1】:

    是的,您可以这样做,如果我正确遵循您的要求,我相信您需要的 URL 重写规则如下。 基本上,

    1. 使用条件将 HTTP_METHOD 匹配为 GET
    2. 使用条件匹配 HTTP_ACCEPT 以确保它以 text/html 开头,因为它们通常还包括编码和其他数据
    3. 确保它不是文件

          <rule name="Rewrite Text Requests">
              <match url=".*" />
              <conditions>
                  <add input="{HTTP_METHOD}" pattern="^GET$" />
                  <add input="{HTTP_ACCEPT}" pattern="^text/html" />
                  <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
              </conditions>
              <action type="Rewrite" url="/index.html" />
          </rule> 
      

    【讨论】:

      猜你喜欢
      • 2017-05-17
      • 2011-12-25
      • 1970-01-01
      • 1970-01-01
      • 2021-05-12
      • 2013-04-01
      • 1970-01-01
      • 2018-06-24
      • 1970-01-01
      相关资源
      最近更新 更多