0

我需要根据用户代理重定向用户。

目前我的 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 来做到这一点。

4

1 回答 1

0

There's a mod_rewrite variable to detect user-agents:

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

but it's not going to help you. There is no way you can match a URL fragment in your htaccess file because the fragment is never sent to the server. URL fragments are completely on the client side, so you're best bet is to add some modifications to your theme to do the user agent check and have it not use fragments if it's from facebook.

于 2013-05-03T10:51:09.123 回答