# ?page=有时会重定向到一个具有不同规范URL的页面

**URL:** <https://meta.discourse.org/t/page-sometimes-redirects-to-a-page-with-a-different-canonical-url/167305>\
**Category:** Bug\
**Created:** [2020 年10 月 15 日 17:38 UTC](https://meta.discourse.org/t/page-sometimes-redirects-to-a-page-with-a-different-canonical-url/167305 "2020-10-15T17:38:41Z")\
**Posts on this page:** 1\
**Showing post:** 1

<div class="post-metadata">

作者： ![RGJ](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/rgj/32/523185_2.png) [@RGJ](https://meta.discourse.org/u/RGJ)\
发布日期： [2020 年10 月 15 日 17:38 UTC](https://meta.discourse.org/t/page-sometimes-redirects-to-a-page-with-a-different-canonical-url/167305/1 "2020-10-15T17:38:41Z")

</div>

我们的一个客户发现了以下与 SEO 相关的问题，我可以在 meta 上复现。

当爬虫访问 Discourse 时，Discourse 会插入类似这样的分页链接 `?page=XX`：

```plaintext
<link rel="next" href="/t/slug/123?page=2">

```

以及

```plaintext
<span itemprop='name'><b><a rel="next" itemprop="url" href="/t/slug/123?page=2">next page </a></b></span>

```

当在浏览器中加载此类页面时，Discourse 会发出 JavaScript 重定向，跳转到 `/t/slug/123/NN` 格式的 URL，其中 NN 是帖子编号。

因此，`https://meta.discourse.org/t/post-rate-limit-trigger-for-a-topic-thats-heating-up/98294?page=2` 会重定向到 `https://meta.discourse.org/t/post-rate-limit-trigger-for-a-topic-thats-heating-up/98294/23`

而 `https://meta.discourse.org/t/post-rate-limit-trigger-for-a-topic-thats-heating-up/98294?page=3` 会重定向到 `https://meta.discourse.org/t/post-rate-limit-trigger-for-a-topic-thats-heating-up/98294/45`

然而， **有时该页面包含的规范 URL 与最初请求的原始页面不一致** 。

在上述示例中，`?page=3` 重定向到第 45 号帖子，而第 45 号帖子的页面包含一个规范 URL `?page=2`：

```plaintext
<link rel="canonical" href="https://meta.discourse.org/t/post-rate-limit-trigger-for-a-topic-thats-heating-up/98294?page=2" />

```

引用客户 SEO 报告中的内容：

> 这会导致规范标签和重定向形成链条，Google 将开始不再信任所设置的规范标签。

我似乎无法找出问题的根源。有时规范 URL 的页码更高，有时更低（如本例所示），有时则是正确的。

我原以为这可能与已删除的帖子或“悄悄话”（whispers）有关，但一个包含大量已删除帖子的主题并未表现出这种行为（例如 `https://meta.discourse.org/t/topic-list-previews/101646?page=5` 跳转到第 471 号帖子（！），而该帖子包含正确的规范 URL `?page=5`）。我认为这可能是一个“差一错误”（off-by-one error）。

---

_[View the full topic](https://meta.discourse.org/t/page-sometimes-redirects-to-a-page-with-a-different-canonical-url/167305)._
