【问题标题】:redirect bots and crawlers via .htaccess [closed]通过.htaccess重定向机器人和爬虫[关闭]
【发布时间】:2015-08-07 19:39:34
【问题描述】:

,我的问题是我想将机器人和爬虫重定向到 site5,并将真正的访问者重定向到 site4,正如您在此架构中看到的那样

http://i.stack.imgur.com/y3oFd.jpg

我做了什么 我创建了一个 .htaccess 文件并将其放在 site1.com/folder/ 中:

    RewriteEngine On 
    RewriteCond %{HTTP_USER_AGENT} Googlebot [OR]
    RewriteCond %{HTTP_USER_AGENT} msnbot [OR]
    RewriteCond %{HTTP_USER_AGENT} Slurp
    RewriteCond %{HTTP_USER_AGENT} facebookexternalhit/1.1 
    RewriteRule ^(.*)$ http://site2.com/xyz/$1 [L,R=301]

我在 site2.com 中做了同样的事情来重定向到 site4.com

我错过了什么吗?

问候

【问题讨论】:

  • 欢迎来到 Stack Overflow!我有点困惑,你写的代码不起作用吗?您需要帮助的具体问题是什么?
  • 嗨 oxguy3 谢谢你的回复,它有效,但我需要帮助才能通过 .htaccess 应用上述架构,
  • 我还是一头雾水,你说它有效但你需要帮助才能应用它?应用它是什么意思?
  • 我会遗漏一些东西,正如您在我的代码 facebookexternalhit/1.1 中看到的那样,但 facebook 爬虫仍然会传递给 site4.com

标签: php .htaccess redirect http-status-code-301


【解决方案1】:

首先,确保您的 apache 设置正常运行。

之后你可以尝试类似的东西

RewriteEngine On 
RewriteCond %{HTTP_HOST} site3.com$ [NC]
RewriteCond %{HTTP_USER_AGENT} Googlebot [OR]
RewriteCond %{HTTP_USER_AGENT} msnbot
RewriteRule ^(.*)$ http://site4.com/$1 [L,R=301]

为了测试,您可以使用简单的 curl 来模拟 google bot 请求:

curl -A "Googlebot/2.1 (+http://www.googlebot.com/bot.html)" http://site3.com

或者只获取标题

curl -X HEAD -i -A "Googlebot/2.1 (+http://www.googlebot.com/bot.html)" http://site3.com

【讨论】:

  • 感谢您的帮助,但如果我将代码编辑为:RewriteEngine On RewriteCond %{REMOTE_ADDR} !^(110\.174\.129\.147|203\.217\ .17\.162) RewriteCond %{HTTP_USER_AGENT} !(Googlebot|msnbot|Surp) [NC] RewriteRule ^(.*)$ site2.com/$1 [L,R=301,NE]
  • 你能用这段代码重写它吗?
猜你喜欢
  • 2013-08-09
  • 1970-01-01
  • 2015-11-16
  • 1970-01-01
  • 1970-01-01
  • 2021-04-05
  • 2016-09-22
  • 2017-11-12
  • 2012-10-04
相关资源
最近更新 更多