homepage Welcome to WebmasterWorld Guest from 54.204.127.59
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
redirect url with htaccess
MrBlack




msg:3458771
 8:48 pm on Sep 23, 2007 (gmt 0)

Hi, I am trying to redirect affiliate urls using htaccess.

The urls that I want to redirect are all exactly the same except for the product id which is placed at the end of the affiliate url, so therefore I am trying to make the product id a variable.

Here is an example of how I want to do the redirection.

http://www.mydomain.com/recommend/abc123456

to

http://myaffiliatemerchant.com/click?p=123&a=123456&g=123456
&url=http://subdomain.productmerchant.com/aa/aa.aspx?CID=1234
&LID=123456&DGC=AF&DGSegHS&ACD=^^&AID=
&DURL=http%253A//subdomain.productmerchant.com/folder/config.aspx
%253Fb%253D%2526c%253Daa%2526bb%253Dabcde1%2526l%253Den%2526oc%253Dabc123456

My htaccess file looks like this:


RewriteEngine on
Options +FollowSymlinks
RewriteBase /

RewriteRule ^recommend/(.*)$ http://myaffiliatemerchant.com/click?p=123&a=123456&g=123456
&url=http://subdomain.productmerchant.com/aa/aa.aspx?CID=1234&LID=123456&DGC=AF&DGSegHS
&ACD=^^&AID=&DURL=http%253A//subdomain.productmerchant.com/folder/config.aspx
%253Fb%253D%2526c%253Daa%2526bb%253Dabcde1%2526l%253Den%2526oc%253D$1 [R=301]

and the link I am using is:

http://www.mydomain.com/recommend/abc123456

However the url is not being redirected properly.

After searching extensively trying to find an answer to this I now assume that there are some characters in the redirected url that are not being parsed in the htaccess.

If anyone suggest a reason why the code above is not working it will be greatly appreciated.

[edited by: jdMorgan at 9:13 pm (utc) on Sep. 23, 2007]
[edit reason] Fixed horizontal scrolling, de-linked. [/edit]

 

jdMorgan




msg:3458782
 9:10 pm on Sep 23, 2007 (gmt 0)

You'll need to unencode the double-encoded characters to start, otherwise mod_rewrite will understand each "%<digit>" sequence as a back-reference to an undefined RewriteCond variable.

Your substitution URL appears to be this, when it is unescaped:

RewriteRule ^recommend/(.*)$ http://myaffiliatemerchant.com/click?p=123&a=123456&g=123456
&url=http://subdomain.productmerchant.com/aa/aa.aspx?CID=1234&LID=123456&DGC=AF&DGSegHS
&ACD=^^&AID=&DURL=http://subdomain.productmerchant.com/folder/config.aspx?b=&c=aa
&bb=abcde1&l=en&oc=$1 [R=301]

(Line breaks added to prevent wrapping here, but not allowed in actual code.)

Jim

[edited by: jdMorgan at 9:13 pm (utc) on Sep. 23, 2007]

MrBlack




msg:3458807
 10:17 pm on Sep 23, 2007 (gmt 0)

Thanks for looking Jim. I tried what you suggested but still no joy. There appears to be a problem somewhere in the first
http://subdomain.productmerchant.com
part of the rewritten url.

I am now trying to go about this a different way as follows:

HTACCESS as below.....

RewriteEngine on
Options +FollowSymlinks
RewriteBase /

RewriteRule ^recommend/(.*)$ http://myaffiliatemerchant.com/click?p=123&a=123456&g=123456&url=$1 [R=301]

and the link code I am using is:

http://www.mydomain.com/recommend/http://subdomain.productmerchant.com/aa/aa.aspx?CID=1234&LID=123456&DGC=AF&DGSegHS
&ACD=^^&AID=&DURL=http://subdomain.productmerchant.com/folder/config.aspx?b=&c=aa
&bb=abcde1&l=en&oc=abc123456

but this resolves to the following url with a 404 not found header

http://myaffiliatemerchant.com/subdomain.productmerchant.com/aa/aa.aspx

P.S Which bb code do i use to stop the links i post here from being clickable?

[edited by: jdMorgan at 10:56 pm (utc) on Sep. 23, 2007]
[edit reason] De-linked [/edit]

jdMorgan




msg:3458821
 10:54 pm on Sep 23, 2007 (gmt 0)

I don't know why you'd get a 404 on their site, but your code won't pass any query string data as it is; RewriteRule cannot 'see' or back-reference a query string, as a query string is not part of a URL-path, but rather, data attached to a URL.

In order to pass the query data that you are 'calling' your rule with, you'll need to handle the query data seperately:

RewriteEngine on
Options +FollowSymlinks
RewriteBase /
RewriteCond %{QUERY_STRING} ^(.+)$
RewriteRule ^recommend/(.+)$ http://myaffiliatemerchant.com/click?p=123&a=123456&g=123456&url=$1?%1 [R=301,L]

Jim

[edited by: jdMorgan at 10:55 pm (utc) on Sep. 23, 2007]

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved