Forum Moderators: phranque

Message Too Old, No Replies

Using htaccess to hide affiliate links

         

tacheman

9:00 pm on Sep 18, 2004 (gmt 0)

10+ Year Member



Hi,
I'm trying to use htaccess to hide affiliate links on my site. Essentially I want to redirect

www.mysite.com/buy/123
to
www.affiliatesite.com/my_id=12345&product_id=123&other_variable=2

With the only thing chaning in the links is the product_id. I've tried the following and neither work:

redirect /buy/(.*)$ [affiliatesite.com...]

And then I tried:

Options +FollowSymLinks
RewriteEngine On
RewriteRule ^buy/(.*)$ [affiliatesite.com...]

And now I'm completely stumped. I've just spend a couple of hours on the web looking for a solution (including the apache site). I don't suppose anybody here has an idea how to do this?

I should add that I have hundreds of URLS to redirect so I have to use a variable in the redirect process (as opposed to typing each redirect into the htaccess file)

Any help would be very much appreciated. Thanks.

jdMorgan

4:04 am on Sep 19, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



And then I tried:

Options +FollowSymLinks
RewriteEngine On
RewriteRule ^buy/(.*)$ http://www.affiliatesite.com/my_id=12345&product_id=$1&other_variable=2

And now I'm completely stumped. I've just spend a couple of hours on the web looking for a solution (including the apache site). I don't suppose anybody here has an idea how to do this?


I'm stumped too, because you didn't say what happened when you tried the code above. We'll need more details in order to help you. Specifically, where do the other variables in the destination URL come from, and what went wrong when you tried the code you posted.

You won't be able to do this transparently with your code -- in other words, the URL in the address bar will change. However, maybe that's not the problem. If it is the problem, then maybe you can proxy the request to the other site. But we need to know precisely what you intend to do, specifically what isn't working, and any errors you see in your server error log (if applicable).

Jim

tacheman

11:14 am on Sep 19, 2004 (gmt 0)

10+ Year Member



Hi Jim,
thanks for the reply. I essentially want to redirect the user to the affiliate site (with the URL in the address bar changing). All of the variables in the affiliate link are fixed and so can be hard coded into the redirect in the htaccess. Only the product ID will change.

I essentially want to implement:

redirect /buy/123456 [affiliatesite.com...]
redirect /buy/7891020 [affiliatesite.com...]
redirect /buy/9876546 [affiliatesite.com...]
. .
. .
. .
And so on

But instead of writing several hunbred redirects as above, I'm trying (and failing) to do it in one line (or a few lines). I think the modrewrite I was trying above was not the correct way to go about it. When I tried the redirect method that I mentioned in my first post I get the following error:

File does not exist: /home/myusername/public_html/buy/123456

I presume that this error is because the redirect isn't associating the 123456 with the (.*)$

Very confused. Thanks again,
Iain.

bull

2:02 pm on Sep 19, 2004 (gmt 0)

10+ Year Member



If you want to redirect, try
RewriteRule ^buy/(.*)$ [affiliatesite.com...] [R=301]

tacheman

2:39 pm on Sep 19, 2004 (gmt 0)

10+ Year Member



Thanks a lot Bull, that worked great. I don't know what I did wrong last night as I'm sure I tried that, must be working too hard ;)