htaccess的301重定向的机器人机器人、重定向、htaccess

2023-09-02 09:39:23 作者:关于傲娇的,高冷傲娇的

我需要.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