机器人的 htaccess 301 重定向 [英] htaccess 301 redirection for the bots

查看:18
本文介绍了机器人的 htaccess 301 重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要 .httaccess 重写规则方面的帮助.我的一位客户说网站 abc.com 应该将来自 google、bing 和 yahoo 搜索引擎机器人的流量(带有 301 重定向)发送到 cba.com 否则显示 index.html(它是一个白页),即如果 Google 机器人正在爬行abc.com 它应该看到重定向到 bcd.com 而不是真正的内容".

I need help in .httaccess rewrite rule. One of my client says "A website abc.com should send traffic (with 301 redirect) from google, bing and yahoo search engigne bots only to cba.com otherwise show index.html (its a white page) i.e if Google robot is crawling abc.com it should see a redirect to bcd.com instead of the real content".

这可能吗?

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

谢谢

推荐答案

您可以在此处获取用户代理列表:http://www.user-agents.org/

You can get a list of user agents here: http://www.user-agents.org/

但是你所拥有的应该可以工作.您可以为主机名添加额外的检查:

But what you have should work. You could add an additional check for the hostname:

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

这些规则在一个空白的 htaccess 文件中对我有用.这是我的要求:

Those rules work for me in a blank htaccess file. This is my request:

GET /something HTTP/1.1
Host: abc.com
User-Agent: Mozilla/5.0 (compatible; Googlebot/2.1; http://www.google.com/bot.html)  

这是阿帕奇的回应:

HTTP/1.1 301 Moved Permanently
Date: Mon, 15 Oct 2012 22:10:55 GMT
Server: Apache
Location: http://bcd.com/something
Content-Length: 289
Content-Type: text/html; charset=iso-8859-1

这篇关于机器人的 htaccess 301 重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆