【问题标题】:Redirect request based on user agent基于用户代理的重定向请求
【发布时间】:2020-03-21 19:57:13
【问题描述】:

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

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

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 来做到这一点。

【问题讨论】:

标签: wordpress .htaccess permalinks


【解决方案1】:

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

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

但它不会帮助你。您无法匹配 htaccess 文件中的 URL 片段,因为片段永远不会发送到服务器。 URL 片段完全在客户端,因此您最好对主题添加一些修改以进行用户代理检查,并且如果它来自 facebook,则不要使用片段。

【讨论】:

  • 感谢您的精彩解释。
猜你喜欢
  • 2014-03-13
  • 2016-03-14
  • 2019-06-20
  • 2011-09-29
  • 2012-01-11
  • 2015-03-28
  • 1970-01-01
  • 2013-04-01
  • 1970-01-01
相关资源
最近更新 更多