简体   繁体   中英

.htaccess 301 redirect just for Google bots

I want to redirect my old domain to a new one but not for users - just for Google bots.

I have manager this code but i am not sure of it. Could you help?

RewriteCond %{HTTP_HOST} oldsite\.pl$ [NC]
RewriteCond %{HTTP_USER_AGENT} Googlebot 
RewriteRule ^ http://newsite.pl [L,R=301]```

What you are implementing is against Google's webmaster guidelines and will get your site penalized such that it doesn't appear in the Google search results at all.

Serving different things to users and Googlebot is called cloaking . Serving redirect to Google and content to users is a form of cloaking called sneaky redirects . To quote Google:

.. some redirects deceive search engines or display content to human users that is different than that made available to crawlers. It's a violation of Google Webmaster Guidelines to redirect a user to a different page with the intent to display content other than what was made available to the search engine crawler. When a redirect is implemented in this way, a search engine might index the original page rather than follow the redirect, while users are taken to the redirect target.

So you shouldn't be doing this if you want to have your site still indexed by Google.

One alternative would be to use canonical tags that point to your new site. Canonical tags are invisible to users but tell search engines to prefer to index one particular copy the site.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM