Welcome to WebmasterWorld Guest from 54.227.83.19

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

redirect url with htaccess

     

MrBlack

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

5+ Year Member



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

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

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member



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

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

5+ Year Member



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

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

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member



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]

 

Featured Threads

Hot Threads This Week

Hot Threads This Month