Reputation: 37
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.
Upvotes: 0
Views: 2876
Reputation: 36043
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]
Upvotes: 0
Reputation: 7720
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';
}
}
Upvotes: 1
Reputation: 43
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.
Upvotes: 0