簡體   English   中英

機器人的htaccess 301重定向

[英]htaccess 301 redirection for the bots

我需要有關.httaccess重寫規則的幫助。 我的一位客戶說:“一個網站abc.com應該將來自google,bing和yahoo搜索引擎的bot的流量(帶有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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM