问题
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
回答1:
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.
来源:https://stackoverflow.com/questions/8653183/facebook-share-showing-escaped-fragment-url-instead-of-hash-version