title: JavaScript redirect based on domain name
body: <p>I am not looking for a simple redirect.</p>
  
  <p>What I am trying to do is this.</p>
  
  <p>Person A loads site BOB.com and clicks a link to page X.<br>
  Person B loads site TIM.com and clicks a link to the same page X.  </p>
  
  <p>Page X has a javascript command on it that says, If user came from site Bob.com then redirect to Bob.com/hello.<br>
  If user came from TIM.com then redirect to Tim.com/hello.<br>
  If user didnt come from ether then redirect to Frank.com/opps.  </p>
  
  <p>This page X is going to handle 404 errors for multiple domains so it will need to ONLY look at the domain name upto ".com". It should ignore everything past the ".com".</p>
  
  <p>This is the script I started with.</p>
  
  <pre><code>&lt;script type='text/javascript'&gt;
  var d = new String(window.location.host);
  var p = new String(window.location.pathname);
  var u = "http://" + d + p;
  if ((u.indexOf("bob.com") == -1) &amp;&amp; (u.indexOf("tim.com") == -1))
  {
  u = u.replace(location.host,"bob.com/hello");
  window.location = u;
  }
  &lt;/script&gt; 
  </code></pre>