Search code examples
javascripthashaffiliate

How to correctly read Javascript hash in custom affiliate URL?


I'm creating a custom affiliate program. I want my links to be as SEO friendly as possible, so I will use a Javascript hash appended to the URL to send the affiliate id, read the affiliate id, store the click, and then 301 re-direct to the page they were linked too. That way we have no canonical issues whatsoever, and every affiliate link passes link juice!

Now, how would I read the following URL?

www.mydomain.com/seo-friendly-url#ref=john

After getting the hash value for ref and adding the click, how would I then 301 re-direct the user back to

www.mydomain.com/seo-friendly-url

Any help is greatly appreciated!


Solution

  • Fragment identifiers (the part after the #) are not sent to the server, so they cannot be read by anything that could then emit an HTTP response (which you need for a 301 redirect).