redirect based of referrer

jlknauff

New member
Aug 25, 2008
237
1
0
Is this the best/right way to redirect based on the referrer?

RewriteCond %{http_referer} ^http://([^.]+\.)*(google)\.com
RewriteRule ^$ somepage.php [R=301,L]
 


Not yet, I'm certain it works...I should clarify my post. If someone comes to the site from a link, directly, etc., then I want them to go through to the site. If they happen to come in through the search results, I want to redirect them to another website.

Would this accomplish that without sending Gbot elsewhere?
 
Looks right then. I've never seen Googlebot send a referer header, so that shouldn't be an issue.

You could probably make the pattern on the RewriteCond line less restrictive, and include some other engines...

RewriteCond %{http_referer} google|yahoo|bing

Oh and I think the RewriteRule is only going to match requests where no path is sent (like hxxp://www.yoursite.comhttp://www.yoursite.com/). If you want this to happen for all pages then try something like

RewriteRule .* somepage.php [R=301,L]
 
Code:
<?php
$ref = $_SERVER['HTTP_REFERER'];
$find = "google";

if(strpos($ref, $find)){

header("Location: affiliate link");

} else {

echo("Suck my balls");

}

?>