Jessica Mary
Jessica Mary

Reputation: 11

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

i want to redirect only if it is a google bot or MSN bot. and only if the url is http://myblog.com/post.html

then i want to make 301 redirect to http://googlebot.com/trolled.htm

PS: I WANT TO MAKE THE REDIRECT USING HTACCESS

in code language

//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 CODE I TRIED

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]

Upvotes: 0

Views: 1109

Answers (1)

anubhava
anubhava

Reputation: 785481

You can only match URI in RewriteRule without protocol and host name part.

Try this rule instead:

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]

Upvotes: 1

Related Questions