1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Need Help With PHP Redirect--Need To Redirect Users Only

Discussion in 'General Programming Chat' started by hellohellosharp, May 10, 2011.

  1. hellohellosharp

    hellohellosharp Power Member

    Joined:
    Dec 8, 2010
    Messages:
    625
    Likes Received:
    552
    Occupation:
    CEO @ CLEANFILES LLC
    Location:
    USA
    Home Page:
    A lot of you have probably seen the sticky post one BH SEO called "Method To Get One Way Backlinks"....I read this and this got me thinking....

    Would there be away to redirect users to one site and all bots to another? I am a complete noob at PHP so any help would be appreciated. Basically just something like

    Code:
    if (visitor is user)
    301 redirect to some site
    else
    301 redirect to a different site
    
    I guess the reverse could also work

    Code:
    if (visitor is any kind of bot)
    301 redirect to some site
    else
    301 redirect to a different site
    
    It seems like this would be somewhat simple. Thanks a ton for any help!! (I will thank all decent replies).
     
  2. gnote

    gnote Registered Member

    Joined:
    Mar 10, 2009
    Messages:
    80
    Likes Received:
    6
    Occupation:
    Programmer
    Location:
    USA
    You can check the users User Agent header against a list of bot strings.

    An example of bot user agents: (I would search to find most recent strings)
    http://www.smart-it-consulting.com/internet/google/googlebot-spoofer/

    Code:
    if ($_SERVER['HTTP_USER_AGENT'] = 'Googlebot/2.1')
    {
    header("location: botsite");
    }
    else
    header("location: realsite");