Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
400 views
in Technique[技术] by (71.8m points)

How can I move a URL via 301 redirect and retain the page's Facebook likes and Open Graph information?

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

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.

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?

To clarify - I have page:

/page1, with an og:url of http://www.example.com/page1

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

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

Question&Answers:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Short answer, you can't.

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)

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

  • 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

Thus:

  1. Existing instances of the object on Facebook will, when clicked, bring users to the correct (new) page via your redirect
  2. The Like button on the (new) page will still produce a like of the correct object (but at the old 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.

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.

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...