【问题标题】:IIS Rewrite rule for mobile devices - Causing loop移动设备的 IIS 重写规则 - 导致循环
【发布时间】:2021-12-06 11:04:03
【问题描述】:

在我的 IIS 应用程序中有一个内部 url,如果用户通过移动设备浏览,我想重定向客户端。

我尝试了以下 URL 重写规则,它会重定向部分,但也会导致重定向循环过多。

  <rule name="Mobile Rewrite" patternSyntax="ECMAScript" stopProcessing="true">
      <match url="(.*)" negate="false" />
      <conditions logicalGrouping="MatchAny" trackAllCaptures="true">
          <add input="{HTTP_USER_AGENT}" pattern="(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino" />
          <add input="{URL}" pattern=".*MMEducation/ScreenEdRegistration" negate="true" />
      </conditions>
      <action type="Redirect" url="MMEducation/ScreenEdRegistration" appendQueryString="false" redirectType="Found" />
    </rule>

谁能建议我如何用重写规则解决这个问题?

【问题讨论】:

    标签: iis url-rewriting


    【解决方案1】:

    条件中的{URL} 与实际中的url 相同。

    例如,移动设备发送请求http://example.com/MMEducation/ScreenEdRegistration。它匹配 {URL} 的条件,IIS 会将其重定向到http://example.com/MMEducation/ScreenEdRegistration。重定向后 URL 永远不会改变。重定向后的 URL 仍然符合条件,IIS 将再次重定向.....循环再循环再循环...

    所以你需要确保重定向的url不符合条件,这样才能解决问题。

    顺便说一下,移动设备的url重定向方法可以参考this

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-08-16
      • 2013-06-25
      • 2019-09-16
      • 1970-01-01
      • 2015-02-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多