如何通过 301 重定向移动 URL 并保留页面的 Facebook 赞和 Open Graph 信息? [英] How can I move a URL via 301 redirect and retain the page's Facebook likes and Open Graph information?

查看:13
本文介绍了如何通过 301 重定向移动 URL 并保留页面的 Facebook 赞和 Open Graph 信息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道 og:url 元标记是开放图中资源的规范 url.

I understand the og:url meta tag is the canonical url for the resource in the open graph.

如果我希望支持资源的 301 重定向,同时保留其在开放图中的位置,我可以使用哪些策略?我不想因为我改变了网址而失去我的喜欢.

What strategies can I use if I wish to support 301 redirecting of the resource, while preserving its place in the open graph? I don't want to lose my likes because i've changed the URLs.

这是存储内容的原始 url 并参考它的最佳方法吗?有没有其他策略可以解决这个问题?

Is the best way to do this to store the original url of the content, and refer to that? Are there any other strategies for dealing with this?

澄清 - 我有页面:

/page1,带有 http://www.example.com/page1og:url

我现在想把它移到/page2,使用 301 重定向到 http://www.example.com/page2

I now want to move it to /page2, using a 301 redirect to http://www.example.com/page2

除了将 og:url 元设置为 /page1 之外,我还有其他选择可以避免丢失喜欢和评论吗?

Do I have any options to avoid losing the likes and comments other than setting the og:url meta to /page1?

推荐答案

简而言之,你不能.

一旦在 Facebook 端创建了对象,它在 Facebook 图表中的 URL 就会固定 - 喜欢和评论与该 URL 和对象相关联;您需要 Facebook 的爬虫可以访问该 URL,以便将来维护该对象.(请注意,对象变得不可访问并不一定会将其从 Facebook 中删除,但实际上您会重新开始)

Once the object has been created on Facebook's side its URL in Facebook's graph is fixed - the Likes and Comments are associated with that URL and object; you need that URL to be accessible by Facebook's crawler in order to maintain that object in the future. (note that the object becoming inaccessible doesn't necessarily remove it from Facebook, but effectively you'd be starting over)

我通常在这里推荐的是(示例http://www.example.com/oldurlhttp://www.example.com/newurl):

What I usually recommend here is (with examples http://www.example.com/oldurl and http://www.example.com/newurl):

  • 在/newpage 上,保持 og:url 标记指向/oldurl
  • 添加一个从/oldurl 到/newurl 的 HTTP 301 重定向
    • 使 Facebook 爬虫免于此重定向
    • 如果请求来自 Facebook 爬虫,则继续为 http://www.example.com/oldurl 上的页面提供元标记.
    • 无需向爬虫返回任何实际内容,只需一个带有适当标签的简单 HTML 页面
    • On /newpage, keep the og:url tag pointing to /oldurl
    • Add a HTTP 301 redirect from /oldurl to /newurl
      • Exempt the Facebook crawler from this redirect
      • Continue to serve the meta tags for the page on http://www.example.com/oldurl if the request comes from the Facebook crawler.
      • No need to return any actual content to the crawler, just a simple HTML page with the appropriate tags

      因此:

      1. Facebook 上对象的现有实例将在点击时通过您的重定向将用户带到正确的(新)页面
      2. (新)页面上的赞"按钮仍会生成正确对象的赞(但在旧 URL 上)

      如果您要移动大量 URL 或完全重写您的 URL 方案,您应该为新文章/产品/等使用新 URL,但如果您想保留喜欢,则需要保持重定向、评论等旧内容.

      If you're moving a lot of URLs around or completely rewriting your URL scheme you should use the new URLs for new articles/products/etc, but you'll need to keep the redirect in place if you want to retain likes, comments, etc on the older content.

      这包括您是否要更改域.

      This includes if you're changing domain.

      这里唯一的问题是在代码中的某处维护旧 URL -> 新 URL 映射,但这在技术上并不困难,只是将来需要维护的额外内容.

      The only problem here is maintaining the old URL -> new URL mapping somewhere in your code, but it's not technically difficult, just an additional thing to maintain in the future.

      顺便说一句,Facebook 爬虫 UA 目前是 facebookexternalhit/1.1 (+http://www.facebook.com/externalhit_uatext.php)

      BTW, The Facebook crawler UA is currently facebookexternalhit/1.1 (+http://www.facebook.com/externalhit_uatext.php)

      这篇关于如何通过 301 重定向移动 URL 并保留页面的 Facebook 赞和 Open Graph 信息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆