gpt4 book ai didi

.htaccess - 男孩的 htaccess 301 重定向

转载 作者:行者123 更新时间:2023-12-02 22:26:24 25 4
gpt4 key购买 nike

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

这可能吗?

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/

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

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 文件中对我有用。这是我的要求:

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

这是 apache 的响应:

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 - 男孩的 htaccess 301 重定向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12904684/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com