title: How to detect a page redirect?
body: <p>I have a page that should be displayed slightly differently if users are coming from a particular link.</p>
  
  <p>I.e.
  The normal page is <code>example.com/foo</code></p>
  
  <p>If someone clicks on a link to <code>example.com/foo-bar</code> I want it redirected to <code>example.com/foo</code>, which can be done with the following line in a .htaccess file:</p>
  
  <pre><code>Redirect permanent /foo-bar /foo
  </code></pre>
  
  <p><br />
  I was planning to then using the following javascript to determine which page a user has come from:</p>
  
  <pre><code>&lt;script type="text/javascript"&gt; 
  document.write(document.referrer);
  &lt;/script&gt; 
  </code></pre>
  
  <p>Which does print out the referrer URL if the user has come from a normal link on the site to <code>/foo</code>. But if they have clicked on a link to <code>/foo-bar</code> it prints out the URL of the page with the link, rather than the <code>/foo-bar</code> address that I need.</p>
  
  <p><br /></p>
  
  <p>Is there a way to redirect a URL to another URL, and detect this on the page redirected to?</p>
  
  <p><br /></p>
  
  <p>(Note that that the difference of content on the page isn't critical, so if the 1% of users with javascript turned off see the wrong thing when they go to <code>/foo-bar</code> it wouldn't be an issue.)</p>