# 添加将 canonical\_url 设置为 embed\_url 的选项

**URL:** <https://meta.discourse.org/t/add-option-to-set-canonical-url-to-embed-url/103915>\
**Category:** Feature\
**Created:** [2018年十二月10日 16:14 UTC](https://meta.discourse.org/t/add-option-to-set-canonical-url-to-embed-url/103915 "2018-12-10T16:14:08Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![gerhard](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/gerhard/32/119479_2.png) [@gerhard](https://meta.discourse.org/u/gerhard)\
**Post date:** [2018年十二月10日 16:14 UTC](https://meta.discourse.org/t/add-option-to-set-canonical-url-to-embed-url/103915/1 "2018-12-10T16:14:08Z")

</div>

From time to time we get requests to set the `canonical` URL of embedded topics to the URL of the blog post. I’ve created a [pull request](https://github.com/discourse/discourse/pull/6741) that does exactly that. It _unconditionally_ uses the URL of the original blog post (`embed_url`) as `canonical` for the topic.

There have been various previous discussions like [Google indexed link not pointing to the correct post](https://meta.discourse.org/t/google-indexed-link-not-pointing-to-the-correct-post/61443) and [Duplicate Content](https://meta.discourse.org/t/duplicate-content/91745) in the past.

After reading those posts I’m not so sure about my solution anymore, so I’d like to get some feedback from you.

- Should this be a configurable? Is there a good reason for keeping the current behavior of always using the topic’s URL as canonical?

- Should the blog post’s URL only be used as canonical for N pages presented to the search bot? After all, only a certain amount of posts is embedded in the blog post. (N probably should be 1)

I’d appreciate your feedback on this. I’m sure there are lots of different use cases out there and I’d like to make an informed decision before I change anything that could affect search engines.

---

<div class="post-metadata">

**Author:** ![Sean\_R](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sean_r/32/72433_2.png) [@Sean\_R](https://meta.discourse.org/u/Sean_R)\
**Post date:** [2018年十二月11日 00:47 UTC](https://meta.discourse.org/t/add-option-to-set-canonical-url-to-embed-url/103915/2 "2018-12-11T00:47:31Z")

</div>

My thought is that if you are copying and re-posting content from a Blog post for any reason conversation or not, the original blog post is the original content and should be pointed to canonically as the original content.

---

<div class="post-metadata">

**Author:** ![Quintin\_Par](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/quintin_par/32/120500_2.png) [@Quintin\_Par](https://meta.discourse.org/u/Quintin_Par)\
**Post date:** [2018年十二月11日 16:41 UTC](https://meta.discourse.org/t/add-option-to-set-canonical-url-to-embed-url/103915/3 "2018-12-11T16:41:43Z")

</div>

> [@gerhard](#):
>
> Should this be a configurable? Is there a good reason for keeping the current behavior of always using the topic’s URL as canonical?

Yes. And by default don’t enable the blog post’s URL as canonical. Let the customer set the switch. Otherwise this is going to change a lot of Search referral traffic all of a sudden.

> [@gerhard](#):
>
> Should the blog post’s URL only be used as canonical for N pages presented to the search bot? After all, only a certain amount of posts is embedded in the blog post. (N probably should be 1)

IMHO, only the blog post linking [top post](https://d.pr/i/R1HE17) should be made canonical. The responses and follow ups should not be.

---

<div class="post-metadata">

**Author:** ![simon](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/simon/32/339122_2.png) [@simon](https://meta.discourse.org/u/simon)\
**Post date:** [2018年十二月11日 17:02 UTC](https://meta.discourse.org/t/add-option-to-set-canonical-url-to-embed-url/103915/4 "2018-12-11T17:02:25Z")

</div>

> [@gerhard](#):
>
> Should this be a configurable?

With the WordPress plugin, sites can choose between publishing an excerpt, or publishing the full post to Discourse. Sites that are only publishing an excerpt might not want the canonical URL set to the blog post.

---

<div class="post-metadata">

**Author:** ![Falco](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/falco/32/179432_2.png) [@Falco](https://meta.discourse.org/u/Falco)\
**Post date:** [2018年十二月11日 17:09 UTC](https://meta.discourse.org/t/add-option-to-set-canonical-url-to-embed-url/103915/6 "2018-12-11T17:09:10Z")

</div>

IMO it should be a _per host_ setting here, default off:

 ![image](https://global.discourse-cdn.com/meta/original/3X/3/7/3703847d045a7644268e286d1d2f74cf9d46b21e.png)

---

<div class="post-metadata">

**Author:** ![gerhard](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/gerhard/32/119479_2.png) [@gerhard](https://meta.discourse.org/u/gerhard)\
**Post date:** [2018年十二月11日 17:13 UTC](https://meta.discourse.org/t/add-option-to-set-canonical-url-to-embed-url/103915/7 "2018-12-11T17:13:57Z")

</div>

> [@Quintin\_Par](#):
>
> IMHO, only the blog post linking [top post](https://d.pr/i/R1HE17) should be made canonical. The responses and follow ups should not be.

That’s not possible. Discourse presents topics as paginated content to crawlers. That’s why I suggested to change only the canonical of the first page.

Yeah, I’m going to make this a per host setting.  
@simon Will this work for the Wordpress plugin as well?

---

<div class="post-metadata">

**Author:** ![simon](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/simon/32/339122_2.png) [@simon](https://meta.discourse.org/u/simon)\
**Post date:** [2018年十二月11日 17:21 UTC](https://meta.discourse.org/t/add-option-to-set-canonical-url-to-embed-url/103915/8 "2018-12-11T17:21:50Z")

</div>

> [@gerhard](#):
>
> Will this work for the Wordpress plugin as well?

Yes, that should work. When a post is published from WordPress it creates a `TopicEmbed` on Discourse, with the `embed_url` set to the post’s permalink.

---

<div class="post-metadata">

**Author:** ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)\
**Post date:** [2018年十二月11日 22:23 UTC](https://meta.discourse.org/t/add-option-to-set-canonical-url-to-embed-url/103915/9 "2018-12-11T22:23:27Z")

</div>

We just got to be careful here… this is a very sharp instrument. If for example wordpress is in “Top N” mode where it show only the best content we can end up setting a canonical to a page that does not have all the overlapping content, this is terrible signal to search engines and can be penalised heavily.

In fact, the whole “collapsing” of OP may make this a bad idea, the OP really should be a complete duplicate of the canonical page, so we may need a different technique there that collapses on client side.

I would not rush anything here.

---

<div class="post-metadata">

**Author:** ![real\_ate](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/real_ate/32/129325_2.png) [@real\_ate](https://meta.discourse.org/u/real_ate)\
**Post date:** [2019年一月17日 21:28 UTC](https://meta.discourse.org/t/add-option-to-set-canonical-url-to-embed-url/103915/13 "2019-01-17T21:28:43Z")

</div>

Howdy folks 👋

I originally wanted to weigh in here and join in the calls for this feature, but after diving in a bit deeper I wanted to share what I learned about how this works (in case anyone missed it like I did initially!)

We’ve just embedded Discourse as the comment system for our blog and I had a little mini freak out when I clicked the “Show full post…” button and saw the whole blog copied without the correct canonical URL 😳

After taking a few deep breaths I went into my “debug mode” and started checking the straight HTML response and checked how much of the post is actually there. As it turns out **only the initial paragraph is included in the HTML** and therefore this is all Google will see. Phew!

Having a second look at it, it makes perfect sense in the way the UX is laid out. I’m assuming the **reason** it’s hidden behind a button is because you want people to be able to read the full post and not affect SEO 👍

I guess initially I was surprised that that “Show full Post…” wasn’t just a link to the original blog 🤔 but I guess it’s an OK way to do it 😂

---

<div class="post-metadata">

**Author:** ![simon](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/simon/32/339122_2.png) [@simon](https://meta.discourse.org/u/simon)\
**Post date:** [2021年二月11日 21:09 UTC](https://meta.discourse.org/t/add-option-to-set-canonical-url-to-embed-url/103915/14 "2021-02-11T21:09:14Z")

</div>

此功能现已通过 `embed set canonical url` 站点设置实现。该设置默认处于禁用状态。启用后，它会将嵌入话题的规范 URL 设置为嵌入内容的 URL。

该功能已存在一段时间了。我很想了解已启用此功能的站点，它如何影响了它们的 SEO 排名。

---

<div class="post-metadata">

**Author:** ![nityeshaga](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/nityeshaga/32/166470_2.png) [@nityeshaga](https://meta.discourse.org/u/nityeshaga)\
**Post date:** [2021年八月11日 07:48 UTC](https://meta.discourse.org/t/add-option-to-set-canonical-url-to-embed-url/103915/15 "2021-08-11T07:48:48Z")

</div>

嘿 @simon，我一直在为我的社区中部分主题设置规范 URL 而寻找解决方案，偶然发现了这篇帖子。

看起来这个设置可能提供了解决方案，但我不明白什么是“嵌入主题”。我尝试在这个社区中搜索相关内容，但没找到任何解释。也许这是一个非常基础的概念。能否请你告诉我什么是嵌入主题，或者如何在 Discourse 社区中嵌入主题？

---

<div class="post-metadata">

**Author:** ![simon](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/simon/32/339122_2.png) [@simon](https://meta.discourse.org/u/simon)\
**Post date:** [2021年八月11日 20:57 UTC](https://meta.discourse.org/t/add-option-to-set-canonical-url-to-embed-url/103915/16 "2021-08-11T20:57:12Z")

</div>

> [@nityeshaga](#):
>
> 看起来这个设置可能提供了解决方案，但我不明白什么是“嵌入主题”。

嵌入主题是指其 `embed_url` 属性被设置为外部网站 URL 的主题。据我所知，这仅在通过 API 将主题发布到 Discourse 时才会发生。例如，Discourse WordPress 插件和 Discourse JavaScript 嵌入代码都会创建嵌入主题。

如果您是从外部网站将主题发布到 Discourse，那么这种方法是有意义的。不过，对于直接在 Discourse 上创建的主题，您将无法使用这种方法。

---

<div class="post-metadata">

**Author:** ![satonotdead](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/satonotdead/32/447830_2.png) [@satonotdead](https://meta.discourse.org/u/satonotdead)\
**Post date:** [2021年十月9日 08:41 UTC](https://meta.discourse.org/t/add-option-to-set-canonical-url-to-embed-url/103915/17 "2021-10-09T08:41:47Z")

</div>

因此，如果我们更改某些博客帖子的标题（例如为了 SEO 目的添加更新日期）和/或为了避免内容重复，这就可以派上用场？

我们确实需要这个功能，因为我们正在使用来自 Drupal 的嵌入内容，这是我第一次遇到这个问题 😐
