0

If a person comes to my site X1 from site X2 then it should redirect to site X3.. if a person directly open the site X1 it should not redirect to site X3. you can use any programming to do this..

WHERE X1 ,X2 and X3 are the three different sites..

Barmar
  • 741,623
  • 53
  • 500
  • 612
  • Something like this? http://stackoverflow.com/questions/3528324/how-do-you-get-the-previous-url-in-javascript – Zze Oct 03 '14 at 23:51
  • What happens if X1 is not directly opened but also isn't coming from site X2? – wired_in Oct 03 '14 at 23:55
  • It's not possible, in general, to know where the user comes from. Some browsers may send a referer header, but don't take it for granted. – Oriol Oct 03 '14 at 23:57

1 Answers1

2

You can check the referer

var ref = document.referrer;
if (ref.match(/^http?:\/\/([^\/]+\.)?SITEX2\.com(\/|$)/i)) {
  window.location.replace("http://SITEX3.com");
}
Bijan
  • 7,737
  • 18
  • 89
  • 149