Regex assistance for htaccess puzzle.
September 27, 2006 4:16 PM Subscribe
Regex assistant for redirecting affiliate links.
Currently my affiliate links are structured like:
http://ecommercesystem.com/app/aftrack.asp?afid=123456&u=mysalespage.com
Where '123456' is a multiple digit affiliate ID and the u variable is where the ecommerce system sends the referred user after they are tagged by the affiliate system.
I'd like to make it easier for my affiliates to be able to create affiliate links in the form:
http://myssite.com/aff/123456/ppp
Where ppp is a multi-letter product code that tells which salespage to send to. I could have multiple lines in the htaccess for each product code 'aaa', 'cat', 'dog', etc. Hopefully this can be done with a polite 301 redirect.
Thanks!
Currently my affiliate links are structured like:
http://ecommercesystem.com/app/aftrack.asp?afid=123456&u=mysalespage.com
Where '123456' is a multiple digit affiliate ID and the u variable is where the ecommerce system sends the referred user after they are tagged by the affiliate system.
I'd like to make it easier for my affiliates to be able to create affiliate links in the form:
http://myssite.com/aff/123456/ppp
Where ppp is a multi-letter product code that tells which salespage to send to. I could have multiple lines in the htaccess for each product code 'aaa', 'cat', 'dog', etc. Hopefully this can be done with a polite 301 redirect.
Thanks!
Response by poster: Yup - I know. I've been hammering on Regex Coach for a few hours now and I'm not having success yet. Hoping there was a RegEx wiz out there that can do this with their eyes closed.
posted by ao4047 at 5:59 PM on September 27, 2006
posted by ao4047 at 5:59 PM on September 27, 2006
RewriteRule ^aff/([0-9]+)/([a-z]+) http://ecommercesystem.com/app/aftrack.asp?afid=$1&u=$2 [L,R=301]
I’m not certain if this is what you’re asking for… What is the relationship between ppp and mysalespage.com? Your description seems to indicate that they aren’t equal, but that there is some mapping. If that is the case, you’ll need more rules.
posted by ijoshua at 6:58 PM on September 27, 2006
Response by poster: Let's say I have three products: ABC, DEF, GHI. All of these products are managed in the same ecommerce system and have the same affiliate system but have differnet salespages.
RewriteRule ^aff/([0-9]+)/ABC http://ecommercesystem.com/app/aftrack.asp?afid=$1&u=www.abcsalespage.com
RewriteRule ^aff/([0-9]+)/DEF http://ecommercesystem.com/app/aftrack.asp?afid=$1&u=www.defsalespage.com
RewriteRule ^aff/([0-9]+)/GHI http://ecommercesystem.com/app/aftrack.asp?afid=$1&u=www.ghisalespage.com
I'll try the example you posted. Thanks!
posted by ao4047 at 8:07 PM on September 27, 2006
RewriteRule ^aff/([0-9]+)/ABC http://ecommercesystem.com/app/aftrack.asp?afid=$1&u=www.abcsalespage.com
RewriteRule ^aff/([0-9]+)/DEF http://ecommercesystem.com/app/aftrack.asp?afid=$1&u=www.defsalespage.com
RewriteRule ^aff/([0-9]+)/GHI http://ecommercesystem.com/app/aftrack.asp?afid=$1&u=www.ghisalespage.com
I'll try the example you posted. Thanks!
posted by ao4047 at 8:07 PM on September 27, 2006
Response by poster: The example from above works - thanks so much ijoshua (and jcruden).
posted by ao4047 at 8:57 PM on September 27, 2006
posted by ao4047 at 8:57 PM on September 27, 2006
http://www.txt2re.com/ is really cool and helpful for people toying with regular expressions. You can enter an example piece of text and it will generate code which matches whatever portions of it you'd like.
posted by websavvy at 9:08 PM on September 27, 2006
posted by websavvy at 9:08 PM on September 27, 2006
This thread is closed to new comments.
http://en.wikipedia.org/wiki/Mod_rewrite
posted by jcruden at 5:03 PM on September 27, 2006