规范 URL 格式问题导致 Facebook 将移动 URL 解释为不同 URL

Canonical URL formatting issue causes Facebook to interpret mobile URL as a different URL

我需要格式化这个规范 URL,但我不知道怎么做!我在网上和这个网站上看了很多,我意识到我需要一个具体的答案。

问题描述:

  1. 我的博客的桌面视图有(比如说)URL:www.x.com/page.html
  2. 同一页面在移动视图中 URL 将是:www.x.com/page.html?m=1
  3. 到目前为止一切都很好,但当我使用 facebook 评论时,问题就来了。它根据这个解析url:www.x.com/page.html

因此,它将第一个 URL 末尾的 ?m=1 识别为完全不同的 URL.

谁能给我一个方法来检查加载页面是 ?m=1 还是 ?m=1然后在发送到 facebook 时删除 ?m=1?

如果解决方案是内联的,我将不胜感激如果它不是内联的,哦,好吧,我只需要一个解决方案现在。

当前使用的代码片段是这样的:

<fb:comments colorscheme='light' expr:href='data:post.url' expr:title='data:post.title' expr:xid='data:post.id' height='110' width='560'/>

Let me break the question into small parts(incase someone is not a native speaker and wants to help/learn about this problem)

  • I want to detect if the loading page has ?m=1 in its URL or not. The canonical URL for this is data:post.url applied as expr:href='data:post.url'
  • If a ?m=1 is detected from data:post.URL , I want to remove it and send the remaining URL into expr:href= so that both my URLs are identified the same when my website displays facebook comments.

Click the image link below to look at this image please. This is the same URL but the comments are being sent to me as if they're from different URLs. I want them to appear under the same thread. This is it--> http://i.stack.imgur.com/M7fK2.png

我在任何地方都找不到这个特定的答案,我希望 一些有创意的解决方案将在此站点中弹出!

在您的代码中

<fb:comments colorscheme='light' expr:href='data:post.url' expr:title='data:post.title' expr:xid='data:post.id' height='110' width='560'/>

使用data:post.canonicalUrl代替data:post.url

这是 Blogger 的布局标签,用于获取博客 post 的规范 URL(这将始终默认为 blogspot.com 域,因此不会有 ccTLD 问题还有)