Search code examples
php.htaccesshttp-redirectgoogle-crawlers

.htaccess / php redirect 301 302 exclusivly for web crawlers


Is there a to redirect only traffic that comes from webcrawlers (mainly google) while maintaining the "normal" user traffic intact ?

My scenario is as follows :

A client had a website on a domain ( www.domain-1.com ) which he sold (the domain). The website is now being moved to a second domain (www.domain-2.com ) .

Is there a way to tell crawlers that the SAME website was moved from domain-1 to domain-2 while not forgetting that domain-1 now has different content of it's own ? (and thus somehow maintaining the old domain-2 indexed links and rankings ?)

Usually, I know in PHP i do a normal permanent redirect sending headers like :

   header('Location: http://www.example.com/', true, 301);
    exit;

But in the above case , I am not sure if I should use :

  • A . 302 / 302 / some other unknown to me
  • B .php / .htaccess

Is that even possible ?

Please any advice would be greatly helpful.


Solution

  • Usually, it considered to be a bad practice to show different content to crawlers than users. Also letting google index the same content in two different domain could hurt the pagerank.

    If you are sure that its a good idea to keep the same content in separate domains, try using the cross-domain rel="canonical" link element to mark the content that got moved from domain-1 to domain-2, leaving the new content unmarked. Google's crawlers should understand these.


    Distilling comment discussion:

    1. If you moving your site (removing the content from the old site eventually) - act according to the Moving your site guide and use 301 redirects as long as you can from the old place to the new. (you can try adjusting the crawl rate to make the links update faster)
    2. If your situation would end up creating duplicate content (the old site keep the content as well) either in-site or on multiple domains, use canonical rels.
    3. Avoid threating search bots differently than users (referred as "cloaking" in google's webmaster docs), it hurts expectations and possibly pageranks.