Forum Moderators: phranque
I've been playing around with this for a few days, and haven't been able to get it to work right. I'm part of an affiliate program, and want to mask my links with mod-rewrite to ensure that my ID number stays in the link...
Here is my .htaccess
Options +FollowSymLinks
RewriteEngine on
RewriteBase /
RewriteRule shoppingcart\/(.*)$ http://www.myaffiliateprogram.com/u/connect/t.asp?id=8905&p=$1
The link in my html is to
http://www.example.net/shoppingcart/product.asp?id=E206
(product.asp?id=E206 is the product page on the affiliate program site I want to end up at)
Unfortunatly my mod-rewrite is taking me to the affiliates main page, and not the page I am requesting. However if I manually enter the URL in my browser http://www.myaffiliateprogram.com/u/connect/t.asp?id=8905&p=product.asp?id=E206
it takes me exactly where I need to go.
Any ideas on what I may be doing wrong?
Thanks!
[edited by: jdMorgan at 4:00 am (utc) on Mar. 15, 2004]
[edit reason] Examplified URL, de-linked [/edit]
Back to the prob at hand. What's happening is the regular expression(.*) is not catching the querystring in the rewriterule. You need to use a rewritecond to get the query string. You use %1, instead of $1 to reference that variable.
Options +FollowSymLinks
RewriteEngine on
RewriteBase /
RewriteCond {QUERY_STRING} ^(.*)$
RewriteRule ^shoppingcart/(.*)$ h*tp://www.example.com/u/connect/t.asp?id=8905&p=$1?%1 [L]
Notes:
[webmasterworld.com...] (similar to your prob)
Notice how I examplified your URL and delinked it. The mods don't want people linking to their sites and they don't want a bunch of dead example URLs. I'm not trying to give you a hard time ;)
Options +FollowSymLinks
RewriteEngine on
RewriteBase /
RewriteCond %{QUERY_STRING} ^(.*)$
RewriteRule ^shoppingcart/(.*)$ h*tp://www.example.com/u/connect/t.asp?id=8905&p=$1?%1 [L]
Slightly different results, but still not what we are looking for.
The link is now redirecting to
ht*p://example.com/product.asp%253fid%3DE206 [note a slightly different string at the end] (it looks like it is getting E206 right at the end, but it is adding in %253f instead of? and %3D inseat of =)
Sensitive stuff!
[edited by: erikcw at 12:54 am (utc) on Mar. 12, 2004]
I think it's because we're trying to capture the?id= part. Maybe we need to just capture the E206 and hardcode the id= part.
RewriteCond %{QUERY_STRING} ^id=(.*)$
RewriteRule ^shoppingcart/(.*)$ h*tp://www.example.com/u/connect/t.asp?id=8905&p=$1?id=%1 [L]
If that one doesn't work, I think it may be because of the two (?) delimiters. Only the first one should be a (?). All the rest should be (&).
BTW You can edit your posts by clicking the "Owner Edit" link under your username.
everything after the first (?) is for the affiliate program management site. Everything after the second? is for the merchants dynamic web page. If I remove the second (?), their site doesn't know what to do with my request.
Are there any other possible solution? I tried escaping the second?, but that didn't work....
RewriteRule ^shop/(.*)$ [example.com...] [L,QSA]
Would also work,
QSA = Query String Append.
Birdman - I didn't spot the query string either on first reading.
NE = not used it off to read the manual ;)
[added]Yep that NE No-Escape is still needed so
RewriteRule ^shop/(.*)$ [example.com...] [L,QSA,NE]
I don't think it would work, but nice example for future though.
[/added]