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

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

问题描述

我需要.httaccess重写规则帮助。我的一个客户说:一个网站abc.com应该从谷歌发送流量(与301重定向),Bing和雅虎搜索engigne机器人只cba.com否则显示的index.html(它的白色页)也就是说,如果谷歌机器人抓取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)  

这是Apache的响应:

And this is apache's response:

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天全站免登陆