0

I am trying to do something and I am not to sure how I can do it!

Basically I want visitors to be re-directed to a different page if they have come from Facebook. So for example if someone shares that page I want future visitors from Facebook to that page to then be re-directed to the home page.

If I can do this through .htaccess or jQuery I am not bothered as long as it works.

vvvvv
  • 25,404
  • 19
  • 49
  • 81

3 Answers3

1

as easy as this

if (document.referrer !== "http://www.facebook.com") {
    document.location.href = "http://www.example.com";
}

or this:

var href = document.location.href;

if (href.indexOf("facebook.com") > 0)

document.location.href = "http://www.example.com"

PHP version:

function url(url){
      return url.match(/:\/\/(.[^/]+)/)[1];
    }

    function check()
    {
      var ref = document.referrer;
      if(url(ref) =='www.facebook.com')
      {

         window.location.href = 'http://example.com';
      }
   }
Devin
  • 7,690
  • 6
  • 39
  • 54
0

You can do this via JavaScript very simply.

if(document.referrer.match("facebook.com")){ 
   window.location = "/";
}

Replace the forward slash with the proper redirection path.

Zach
  • 43
  • 3
0
if (document.referrer !== "http://www.facebook.com") {
    document.location.href = "http://www.google.com";
}

or in htaccess

RewriteEngine on
RewriteCond %{HTTP_REFERER} ^http://www\.facebook\.com [NC]
RewriteRule ^(.*)$ http://www.google.com/ [R]
davidcondrey
  • 34,416
  • 17
  • 114
  • 136