2013-05-03 48 views
0

我需要根据Useragent重定向用户。基于用户代理的重定向请求

目前我的WordPress的网站使用基于Ajax的主题。所以url格式是

http://www.example.com/#!/my_first_post/ 

我目前的htaccess代码如下。

# BEGIN WordPress 
<IfModule mod_rewrite.c> 
RewriteEngine On 
RewriteBase/
RewriteRule ^index\.php$ - [L] 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule . /index.php [L] 
</IfModule> 

# END WordPress 

这就是我需要帮助的事情:

if (user agent == "facebookexternalhit/1.1 (+http://www.facebook.com/externalhit_uatext.php)"){ 
redirect the url without hashes 
ex:http://www.example.com/my_first_post/ 
} 

我需要做到这一点使用htaccess的。请帮帮我。

+0

Hashbangs ... Yuck ... http://www.webmonkey.com/2011/02/gawker-learns-the-hard-way-why-hash-bang-urls-are-evil/ – 2013-05-03 10:00:57

回答

0

有一个mod_rewrite的变量来检测用户代理:

RewriteCond %{HTTP_USER_AGENT} facebookexternalhit/1\.1 [NC] 

,但它不会帮助你。您无法在您的htaccess文件中匹配URL片段,因为片段从未发送到服务器。网址片段完全位于客户端,因此最好的办法是对您的主题添加一些修改,以便执行用户代理检查,并让它不使用来自Facebook的片段。

+0

感谢很好的解释。 – 2013-05-03 11:46:24