HtAccess 重定向,如果 Google/MSN bot 并且仅适用于 URL


HtAccess Redirect, if Google/MSN bot and only for a url

我只想重定向,当它是谷歌机器人或MSN机器人时。并且仅当 URL http://myblog.com/post.html

然后我想让 301 重定向到 http://googlebot.com/trolled.htm

PS:我想使用 HTACCESS 进行重定向

在代码语言中

//code is worng but to make you understand my question
if(googlebot OR msn)
{
   if url(http://myblog.com/post.html){
            redirect (`http://googlebot.com/trolled.htm)
   }
}

我尝试过的访问代码

RewriteEngine On 
RewriteCond %{HTTP_HOST} myblog.com$ [NC]
RewriteCond %{HTTP_USER_AGENT} Googlebot [OR]
RewriteCond %{HTTP_USER_AGENT} msnbot
RewriteRule http://myblog.com/post.html http://googlebot.com/trolled.html [L,R=301]

您只能在没有协议和主机名部分的情况下匹配RewriteRule中的 URI。

请尝试以下规则:

RewriteEngine On 
RewriteCond %{HTTP_HOST} myblog'.com$ [NC]
RewriteCond %{HTTP_USER_AGENT} (msnbot|Googlebot) [NC]
RewriteRule ^post'.html$ http://googlebot.com/trolled.html [L,R=301]