How would I do this? (redirect script)

Status
Not open for further replies.

mberman84

New member
Jan 17, 2007
706
14
0
Los Angeles
basically, what i want to do is redirect all visitors that DO NOT come from website.com. i want to have all variations of website.com redirect to A, and any other website redirect to B.

so, website.com, www.website.com, sub1.website.com, website.com/dir1 etc etc all go to A


and any other referrer goes to B. how do i do this?
 


Please note, this is untested...

Basically, you just change the case '<valuehere>' to whatever the referer is you want to redirect to some special place - The default is there to catch any that dont fall on any of the cases.

Code:
<?php

if(!empty($_SERVER['HTTP_REFERER'])) {
    $referer = parse_url($_SERVER['HTTP_REFERER']);

    switch($referer['host']) {
        case 'website.com':
        $location = 'http://sometime.com';
        break;

        default:
        $location = 'http://someothersite.com';
        break;
    }

     header('Location: '.$location);
     exit;
}

?>
 
Mmmk - parse_url() returns full hostname including subs.. This should take care of that...

Code:
<?php

if(!empty($_SERVER['HTTP_REFERER'])) {
    $referer = parse_url($_SERVER['HTTP_REFERER']);

    preg_match('/[^.]+\.[^.]+$/', $referer['host'], $match);

    switch($match[0]) {
        case 'website.com':
        $location = 'http://sometime.com';
        break;

        default:
        $location = 'http://someothersite.com';
        break;
    }

     header('Location: '.$location);
     exit;
}

?>
 
Taken from Nickycake's Facebook Cloaking Script:

<?php
$cloaked_url = "http://www.google.com"; // devs go here
$normal_url = "http://www.yahoo.com"; // everyone else goes here

$tracking_ref = $_SERVER['HTTP_REFERER'];

if(strpos($tracking_ref,"dev.facebook")){
Header( "HTTP/1.1 301 Moved Permanently" );
Header( "Location: " . $cloaked_url );
} else {
Header( "HTTP/1.1 301 Moved Permanently" );
Header( "Location: " . $normal_url );
}
?>
 
Status
Not open for further replies.