【问题标题】:Troubleshoot Redirect Loop affecting only Mobile Devices对仅影响移动设备的重定向循环进行故障排除
【发布时间】:2021-02-11 09:33:50
【问题描述】:

我正在使用 IIS10 和 URL-Rewrite,由于某种原因,我的网站有一个重定向循环,但仅在移动设备上。无论是哪部手机、它连接的网络或清除缓存的次数,该网站都不会在任何移动设备的任何浏览器上加载。我用iphone、android、chrome、firefox、safari测试过都一样。

这是我在 web.config 中的规则

<rewrite>
      <rules>
        <rule name="CanonicalHostNameRule1">
          <match url="(.*)" />
          <conditions logicalGrouping="MatchAll">
            <add input="{HTTP_HOST}" pattern="^example\.com$" negate="true" />
            <add input="{HTTP_HOST}" pattern="^(.*)\.example\.com$" negate="true" />
          </conditions>
          <action type="Redirect" url="http://example.com/{R:1}" />
        </rule>
        <rule name="Redirect to HTTPS" stopProcessing="true">
          <match url="(.*)" />
          <conditions>
            <add input="{HTTPS}" pattern="^OFF$" />
          </conditions>
          <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="SeeOther" />
        </rule>
      </rules>
    </rewrite>

我在同一台机器上托管了其他网站,它们具有类似的 URL 重写规则,可以正常工作,没有问题。

即使我关闭了所有规则,我仍然会在移动设备上获得重定向循环。

任何有关如何解决此问题的工具、提示/技巧将不胜感激!


更新:来自 Fiddler 的信息

RAW:

HTTP/1.1 301 Moved Permanently
Cache-Control: private
Content-Type: text/html; charset=utf-8
Location: http://example.com/
X-Redirect-Reason: Wrong Portal Alias Requested
Set-Cookie: dnn_IsMobile=True; path=/; HttpOnly
Set-Cookie: language=en-US; path=/; HttpOnly
X-XSS-Protection: 1; mode=block
X-Frame-Options: SAMEORIGIN
Date: Thu, 29 Oct 2020 13:19:56 GMT
Content-Length: 142

<html><head><title>Object moved</title></head><body>
<h2>Object moved to <a href="http://example.com/">here</a>.</h2>
</body></html>

标题:

**Response Headers**
HTTP/1.1 301 Moved Permanently
**Cache**
Cache-Control: private
Date: Thu, 29 Oct 2020 13:19:56 GMT
**Cookies/Login**
Set-Cookie: dnn_IsMobile=True; path=/; HttpOnly
Set-Cookie: language=en-US; path=/; HttpOnly
**Entity**
Content-Length: 142
Content-Type: text/html; charset=utf-8
**Miscellaneous**
X-Redirect-Reason: Wrong Portal Alias Requested
**Security**
X-Frame-Options: SAMEORIGIN
X-XSS-Protection: 1; mode=block
**Transport**
Location: http://example.com/

我看到了Wrong Portal Alias Requested,但不确定是什么原因造成的?

【问题讨论】:

  • 尝试在您的测试移动设备上打开私人浏览器选项卡,因为您之前的尝试可能会被缓存并导致此类问题。
  • 嗨 Lex,我已经在连接到我的路由器和蜂窝网络的不同设备上完成了这项工作。我还让不同地点的其他人在他们的设备和网络上进行了测试,结果相同。
  • 那你得用Fiddler之类的工具来捕捉手机浏览器的实际流量docs.telerik.com/fiddler/Configure-Fiddler/Tasks/…然后从中看出什么奇怪的东西。
  • 您能分享您的网站绑定吗?您是否在您的网站上设置了任何其他代码进行重定向?你使用什么样的证书?您是在服务器级别还是站点级别应用此规则?你能分享一下你失败的请求追踪结果吗?
  • @JalpaPanchal 我将很快发布失败的请求跟踪结果,没有其他代码在重定向,SSL 是通配符 SSL,我在网站上有很多绑定我将创建一些示例来展示你。

标签: iis-10 url-rewrite-module


【解决方案1】:

感谢 LexLi,他让我找到了正确的方向。 Fiddler 很有帮助。

是的,该网站是在 DNN CMS 应用程序上构建的,问题是在 DNN 中有一个表 portalsettings 有一个名为 DefaultPortalAlias 的设置,此设置中有错误的值。

此外,在 DNN 的 PortalAlias 表中,还有 bit 字段用于 IsPrimary,在我的情况下,IsPrimary 设置为别名的 www. 版本而不是 non-www.,在 IIS 中我的网址重写规范规则指向non-www. 绑定,这就是导致循环的原因。我不确定为什么它只影响移动设备,但在这些更改之后它现在可以工作了。

感谢@Lex Li 的见解!

【讨论】:

    猜你喜欢
    • 2010-10-23
    • 2020-10-02
    • 2023-04-07
    • 1970-01-01
    • 2020-05-10
    • 1970-01-01
    • 2021-06-23
    • 1970-01-01
    • 2012-02-12
    相关资源
    最近更新 更多