I have a page that should be displayed slightly differently if users are coming from a particular link.
I.e.
The normal page is example.com/foo
If someone clicks on a link to example.com/foo-bar I want it redirected to example.com/foo, which can be done with the following line in a .htaccess file:
Redirect permanent /foo-bar /foo
I was planning to then using the following javascript to determine which page a user has come from:
<script type="text/javascript">
document.write(document.referrer);
</script>
Which does print out the referrer URL if the user has come from a normal link on the site to /foo. But if they have clicked on a link to /foo-bar it prints out the URL of the page with the link, rather than the /foo-bar address that I need.
Is there a way to redirect a URL to another URL, and detect this on the page redirected to?
(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 /foo-bar it wouldn’t be an issue.)
change your redirection code to:
and then in /foo: