0

I know how to pass a simple URL as a string variable through a URL (i.e. http://example.com/?site=http://amazon.com), however I have a bit more of a complicated situation which I cannot figure out.... what if the url I want to be passing contains variables of its own? i.e. http://amazon.com/?ref=00112233&size=med ?

Background: I have a Wordpress site where I have a box to input an affiliate link, which is attached to a button that a user would click. Rather than just putting in the affiliate link so that they are sent directly to the site, I instead want to pass the affiliate link to a php script which would alter the affiliate link based on their geographic location, and then redirect them to the altered location. For example, my affiliate link is: http://amazon.com/?ref=00112233&size=med ... I want to pass that to my script, and then say if the user was from Canada it would alter the link to be http://amazon.ca/?ref=998877&size=med (switches domain and referral #) and send them to that location.

When I input the following URL to attach to my button, http://example.com/?site=http://amazon.com/?ref=00112233&size=med the redirect doesn't work..FF comes up with a msg saying the redirect is setup in a way that will never complete. The redirect works fine if the site value is something simple like 'http://amazon.com'... so I'm assuming it's because the affiliate link itself contains a ? already.

Any thoughts on how to get around this? I can't find anything that addresses this circumstance.

Hopefully that wasn't too confusing--let me know if any clarification is needed.

Thank you!

Mark
  • 739
  • 1
  • 9
  • 15
  • 2
    possible duplicate of [URL/HTML Escaping/Encoding](http://stackoverflow.com/questions/4782988/url-html-escaping-encoding) – Leigh Sep 01 '14 at 21:56
  • I'm not sure how I can make use of that in my case though, as I am not setting the URL's dynamically, I'm manually entering them into a WordPress field... or are you suggesting that I somehow encode the URL as a separate process, and then manually insert the encoded URL? – Mark Sep 01 '14 at 22:02
  • I guess I would suggest that you manually make the "wordpress field" encode it (urlencode()). Can't help beyond that, not touching wordpress with a 50ft pole. – Leigh Sep 01 '14 at 22:06
  • Your wordpress templates will have code that gets the data you enter back out of the database, and include it in the html. You can edit this code to use `urlencode` – Steve Sep 01 '14 at 22:08

0 Answers0