如何处理Facebook的共享/像hashbang网址? [英] How to handle facebook sharing/like with hashbang urls?
问题描述
我建立一个网站,在主页上我会打开其他的URI,在网站上为一个收藏夹(AJAX),我想用HTML5推动国家和哈希刘海作为后备管理状态的变化。
I am building a website where from the homepage i will open some other URI on the website into a lightbox (AJAX), and i want to use HTML5 push state and hash bangs as a fallback to manage changes of states.
现在我想的网址是抓取和Facebook共享/可爱。
Now i want the urls to be crawlable and Facebook shareable/likeable..
如果用户浏览器支持HTML5推送状态,没有任何问题,他可以分享的网址(例如:的http:// MYSERVER /例子
)和Facebook会发现适当OG METAS的静态内容。
If the user browser supports HTML5 push state, no problem, he can share the URL (for example : http://myserver/example
) and Facebook will find the appropriate OG metas in the static content.
但是,如果用户使用了HTML4浏览器,他将有一个像 HTTP网址:// MYSERVER /#/例子
。我希望他能够通过Facebook反正分享...
But if the user uses a HTML4 browser, he will have a url like http://myserver/#!/example
. and i want him to be able to share it through facebook anyway...
现在它看起来像Facebook的支持_escaped_fragment_替换方法,所以我虽然我会简单地重定向从 http请求:// MYSERVER / _escaped_fragment _ = /例如
以的http:// MYSERVER /例子
每个人都应该是快乐的......
Now it looks like Facebook supports the _escaped_fragment_ replacement method, so i though i would simply redirect requests from http://myserver/?_escaped_fragment_=/example
to http://myserver/example
and everybody should be happy…
所以我增加了一个重写条件我htaccess的:
So i added a rewrite condition to my htaccess :
RewriteCond %{QUERY_STRING} ^_escaped_fragment_=([^&]*)
RewriteRule .* http://%{HTTP_HOST}/%1? [R=301,L,NE]
我的问题是,我不能使它与Facebook的合作,与Facebook棉短绒似乎URL的一部分hashbang后百分号逃避所有的时间,导致类似的网址
的http:// MYSERVER /%2Fexample
该土地为404: - (
My problem is that i can't make it work with Facebook, with Facebook linter it seems to percent-escape all the time the part of the URL after the hashbang, resulting in urls like
http://myserver/%2Fexample
which lands to a 404 :-(
有谁知道如何欺骗Facebook的进入不会逃避这部分的网址? 我可以做一些对URL重写的一面?
Does anybody knows how to trick Facebook into not escaping this part of the URL ? Can i do something on the apache mod_rewrite side ?
我也开到任何其他有效的AJAX抓取/可爱的URL策略;)
I am also open to any other valid ajax crawlable/likeable URL strategy ;)
推荐答案
我最终使用PHP的头()重定向,它完美的作品:
i ended using a php header() redirect, which works perfectly :
if(isset($_GET['_escaped_fragment_'])) {
Header( "HTTP/1.1 301 Moved Permanently" );
header('Location: http://'.$_SERVER['HTTP_HOST'].$_GET['_escaped_fragment_']);
die();
}
我不知道为什么我得到htaccess的重写条件时在做转义字符。
I don't know why i got escaped characters when doing it with the htaccess rewrite condition.
这篇关于如何处理Facebook的共享/像hashbang网址?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!