Redirect Problem - Referral Querystring in URL

Discussion in 'PHP' started by TechEvangelist, May 12, 2008.

  1. #1
    I ran into an account that was using a referral querystring in all of their AdWords ads to identify the source for traffic. The the site tanked in Yahoo and all of the URLs listed in Yahoo contain the following referral URL. AdWords was the only place where these URLs were used.

    www.domainname.com/?referral=google
    
    Code (markup):
    We removed the ?referral=google portion from all of the AdWords ads several months ago, but Yahoo is still retaining them. Even though the querystring was non-functional (it didn't do anything), it is still a valid URL that lands the user on the site's home page.

    We want to use a 301 redirect to clean up the URLs in Yahoo. We've tried several variations, but none appear to work. I think the question mark is screwing things up, but even when I escape it with a backslash the rewrite doesn't do anything.

    The following do not work.

    redirect 301 /?referral=google http://www.domainname.com/
    
    redirect 301 /\?referral=google http://www.domainname.com/
    
    RewriteCond %{HTTP_HOST} ^www\.domainname\.com/\?referral=google
    RewriteRule ^(.*)$ http://www.domainname.com/ [R=301,L]
    
    Code (markup):
    Does anyone have any ideas as to how to get this to work correctly?
     
    TechEvangelist, May 12, 2008 IP
  2. xrvel

    xrvel Notable Member

    Messages:
    918
    Likes Received:
    30
    Best Answers:
    2
    Trophy Points:
    225
    #2
    If i understand your problem correctly, what about letting the PHP to do the redirection and not the .htaccess.

    For example, from yourdomain.com, you want to redirect all incoming traffic that has something in its URL.

    Create an index.php

    
    <?php
    // Put this in top of your index.php
    if (isset($_GET['referral'])) {// if need to be redirected
       header('Location: http://www.yahoo.com');// redirects
       exit();// out from script
    }
    
    
    // put your other code, etc
    ?>
    
    PHP:
     
    xrvel, May 14, 2008 IP
  3. suresh2220

    suresh2220 Peon

    Messages:
    20
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Try out Either these 2 codes

    301 Redirect:
    <?
    header("HTTP/1.1 301 Moved Permanently");
    header("Location: http://www.suresh-mobileweb.blogspot.com/");
    ?>

    302 Redirect:
    <?
    header("HTTP/1.1 302 Moved Temporarily");
    header("Location: http://www.suresh-mobileweb.blogspot.com/");
    ?>

    with regards,
    Suresh A,
     
    suresh2220, May 14, 2008 IP
  4. TechEvangelist

    TechEvangelist Guest

    Messages:
    919
    Likes Received:
    140
    Best Answers:
    0
    Trophy Points:
    133
    #4
    Thanks for the help, but neither solution solves the problem. I need to filter out and remove "referral=google" by doing a 301 redirect ONLY when that specific querystring is attached to any URL in the site. It needs to be a 301 redirect to remove the querystrings from Yahoo.

    I did find a solution that looks like it works using mod_rewrite and the .htaccess file.
     
    TechEvangelist, May 15, 2008 IP
  5. suresh2220

    suresh2220 Peon

    Messages:
    20
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    That Great , Finally you got your result.

    with regards,
    Suresh Kumar A
    http://suresh-mobileweb.blogspot.com
     
    suresh2220, May 15, 2008 IP
  6. myhart

    myhart Peon

    Messages:
    228
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #6
    I have a similar problem with the "question mark" causing one of my sites to have a duplicate homepage indexed on Google. If the mod_rewrite solution worked ok would you mind sharing the solution. I have spent several hours looking and this is the only mention that I can find of the problem. Thanks in advance!!!
     
    myhart, Jun 3, 2008 IP
  7. myhart

    myhart Peon

    Messages:
    228
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #7
    I certainly don't mean to sabotage this tread! However I had asked a similar question over on the Apache forum before seeing this thread. So rather than post the solution I found twice I will include a link to that thread. Hope that is ok with everyone and that the following solution helps someone else!

    http://forums.digitalpoint.com/showthread.php?p=8021630#post8021630
     
    myhart, Jun 4, 2008 IP
  8. subpuppy

    subpuppy Peon

    Messages:
    17
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    So what was the solution?
     
    subpuppy, Oct 1, 2008 IP