我想重定向只有它是谷歌机器人或MSN机器人。
并且仅当网址为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)
}
}
我试过的HTACCESS代码
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]
答案 0 :(得分:1)
您只能匹配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]