Web Hosting Talk







View Full Version : Adding affiliate ID to all outgoing links


ThatScriptGuy
11-16-2005, 03:49 PM
My client is asking me to do something which is, in fact, a good idea. He is wanting to use a script which is zend encoded. This script basically allows members to add stocks and certificates to their account and also links to items they are selling on ebay. But that is irrelevant. Is there any way, with an .htaccess file (since the script is zend encoded) to add characters to a URL if the URL is going to a certain site? I am assuming that the script creates a link like http://oursite.com/redirect.php?page=ebay.com/members_item_number

And what my client wants is to add ?affiliateid=###### Can this be done with an .htaccess file?
Thank you.

funkytaco
11-16-2005, 10:50 PM
Use mod_rewrite and an .htaccess file, put this in it:

Options +FollowSymLinks
RewriteEngine on
RewriteRule ^redirect/([0-9]+)/(.*)$ /redirect.php?page=http://$2/$1 [L]
The URL I typed:
http://mysite.com/redirect/123/somesite.com
I tested it and this is the outcome i see in phpinfo():
REDIRECT_QUERY_STRING page=http://somesite.com/123


Using the ID (which was 123 in this example) before the site may help with tracking.

Hope this helps.

ThatScriptGuy
11-16-2005, 10:53 PM
OK, so if a script links to

http://www.ebay.com/users_store
then this mod_rewrite code will turn it into
http://www.ebay.com/users_store?affiliateid=######## ?
The affiliate ID will always be static. The webmaster is looking to earn income from hits to ebay from his site.
Kevin

funkytaco
11-16-2005, 11:56 PM
The affiliate id needs to be in the URL, it's not going to be included unless you put it in the url.

i.e.

http://webmasters-site.com/redirect/###/any_url.com
will be "re-written" to:
http://webmasters-site.com/redirect.php?page=http://any_url.com/###

If he doesn't need an affiliate id in the redirect URL (which may make tracking harder), he could use

Options +FollowSymLinks
RewriteEngine on
RewriteRule ^redirect/(.*)$ /redirect.php?page=http://$1 [L]

http://webmasters-site.com/redirect/any_url.com
will be "re-written" to:
http://webmasters-site.com/redirect.php?page=http://any_url.com

He then needs to code redirect.php to save how many referrals are being sent to each ebay store or wherever he is referring people to.

ThatScriptGuy
11-17-2005, 12:02 AM
I understand what you're doing, but don't know if it's quite what I need to do. Please let me simplify. Let's say his affiliate ID is 859. I Need EVERY URL going to eBay to be rewritten to have his ID added to the end of it.

IE: Script links to http://www.ebay.com, but the .htaccess catches it and changes it to http://www.ebay.com?affiliateid=859

How would I go about doing that? Is that possible with .htaccess? So far, I'm not able to pull enough from your mod_rewrite examples to gain anything (which I'm usually quite good at).
Thanks for your help.

funkytaco
11-17-2005, 12:07 AM
Ok, i see what you're say now. I think? LOL :)

Options +FollowSymLinks
RewriteEngine on
RewriteRule ^redirect.php?page=(.*)$ /new_redirect.php?page=http://$1 [L]

Then make your new_redirect.php handle redirects.

funkytaco
11-17-2005, 12:20 AM
Ok, sorry we posted at nearly the same time.

For the last example:

RewriteRule ^redirect.php?page=(.*)$ /new_redirect.php?page=http://$1 [L]

just change that to

RewriteRule ^redirect.php?page=(.*)$ /new_redirect.php?page=http://$1?affiliateid=859 [L]

You could probably catch eBay.com explicity in the URL, too, but why bother, it causes more cpu processing. :)

Test this first by putting a phpinfo() in the new_redirect.php, so you can make sure its redirecting to the write page or just echo $REDIRECT_QUERY_STRING

This will only work if the link is using redirect.php?page=http://www.ebay.com/

If they are making a direct link to ebay.com you are probably out of luck.

ThatScriptGuy
11-17-2005, 12:27 AM
Thank you thank you thank you. Of course it was as easy as that (slaps forehead). Now, the reason I want to catch ebay.com in the URL. A: What if the script does not use a redirect script and instead links directly to ebay? I realize that I could change ^redirect.php?page=(.*)$ to just ^(.*)$ but I don't want every URL to have the AID added. So, just in case, how would I modify the htaccess to catch the ebay.com in the URL so that I was only adding the AID for ebay?
Thanks again.

michael-lane
11-17-2005, 04:50 AM
do ebay have an affilia system?

ThatScriptGuy
11-17-2005, 11:19 AM
http://affiliates.ebay.com

funkytaco
11-17-2005, 04:04 PM
Well if it was in PHP and wasn't encoded
You could look at:
http://us2.php.net/manual/en/function.ob-start.php

That would allow you to re-write any html data before it is sent from the web server to the web client. I can't say it would be possible with an encoded file.

ThatScriptGuy
11-17-2005, 07:13 PM
if it weren't encoded, i could do it in php with no problem ;-)

thank you for your help though.