Facebook 分享显示 _escaped_fragment_ URL 而不是哈希版本

发布于 2024-12-23 06:30:18 字数 497 浏览 3 评论 0原文

我创建了一个单页应用程序。所有深层链接均采用 mysite.com/#!/entry_title 的形式。这允许 Google(和 Facebook)检查该页面内容的备用 URL。

我已经设置了服务器端检查以确定 Google 或 Facebook 是否正在查找此页面的 HTML 快照。如果是这样,它会发送一个包含必要的 Facebook og 元标记的不同标头。

问题就在这里。如果我将 URL 之一 (mysite.com/#!/entry_title) 粘贴到状态框中,则显示的 URL 是 HTML 快照 URL (mysite.com/?_escaped_fragment_/entry_title)。

HTML 快照页面上的 og:url 元标记设置为 mysite.com/#!/entry_title。

如何使共享器显示 URL 的 mysite.com/#!/entry_title 版本而不是 HTML 快照版本?

提前致谢!

  • 布雷特

I've created a single-page app. All deep links are in the form of mysite.com/#!/entry_title. This allows Google (and Facebook) to check an alternate URL for the content of that page.

I've setup a server-side check to determine if Google or Facebook is looking for the HTML snapshot of this page. If so, it sends a different header containing the necessary Facebook og meta tags.

Here's the problem. If I paste one of my URLs (mysite.com/#!/entry_title) into my status box the URL that gets displayed is the HTML snapshot URL (mysite.com/?_escaped_fragment_/entry_title).

The og:url meta tag on the HTML snapshot page is set to mysite.com/#!/entry_title.

How can I make the Sharer display the mysite.com/#!/entry_title version of the URL instead of the HTML snapshot version?

Thanks in advance!

  • Brett

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夏末染殇 2024-12-30 06:30:18

我已经弄清楚了这一点,并认为我会为其他人发布答案。

诀窍是为 Google/Facebook 设置重定向以转到更漂亮的 URL。因此,任何形式的 URL

mysite.com/?_escaped_fragment_/entry_title 

都会被重定向到更漂亮的内容,例如

mysite.com/view/entry_title

当有人分享我的动态 URL 之一时,Facebook 会请求该页面的 _escaped_fragment_ 版本,并被重定向到我的更漂亮的 URL (mysite.com/view/entry_title),即Facebook 帖子中显示的内容。

为了确保人们始终共享我的动态 URL,我在 mysite.com/view/entry_title 页面上设置了 javascript 重定向,以重定向回 mysite.com/#!/entry_title 页面。

虽然这不会显示 Facebook 共享中的动态 URL,但它会显示比 _escaped_fragment_ 版本更漂亮的 URL,并迫使人们回到我希望人们共享的动态 URL。

I've figured this out and thought I'd post the answer for others.

The trick is to setup a redirect for Google/Facebook to go to a prettier URL. So any URL in the form of

mysite.com/?_escaped_fragment_/entry_title 

gets redirected to something prettier like

mysite.com/view/entry_title

When someone shares one of my dynamic URLs, Facebook requests the _escaped_fragment_ version of the page, and gets redirected to my prettier URL (mysite.com/view/entry_title), which is what gets shown in the Facebook post.

To make sure people always share my dynamic URL I've setup a javascript redirect on the mysite.com/view/entry_title pages to redirect back to the mysite.com/#!/entry_title pages.

While this doesn't show the dynamic URL in the Facebook Share, it shows a prettier URL than the _escaped_fragment_ version and forces people back to the dynamic URL that I want people to share.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文