Forum Moderators: phranque

Message Too Old, No Replies

Multiple Referring URL Redirection

referer redirection

         

mtnmansierras

11:44 am on Jun 16, 2010 (gmt 0)

10+ Year Member



I have a redirection setup that redirects traffic to my domain to another domain. The traffic going to my domain is from an article directory. I want to be able to track which articles are generating the most traffic by tracking a unique "id" in the redirection url associated with each article.

Can I do something like this?

RewriteEngine on
RewriteCond %{HTTP_referer} ^www.articledirectory.com/?article1$ [NC]
RewriteRule ^/?article1$ "http://www.new-domain.com/page&id1" [R=301,L]
RewriteCond %{HTTP_referer} ^www.articledirectory.com/?article2$ [NC]
RewriteRule ^/?article2$ "http://www.new-domain.com/page&id2" [R=301,L]
RewriteCond %{HTTP_referer} ^www.articledirectory.com/?article3$ [NC]
RewriteRule ^/?article3$ "http://www.new-domain.com/page&id3" [R=301,L]


Thanks,
Mike

jdMorgan

1:25 pm on Jun 16, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Escape the literal periods in patterns by preceding them with "\" -- ^www.articledirectory.com/?article1$ should be ^www\.articledirectory\.com/?article1$

Quotes on the redirect target URL are not needed.

Either the requested URL-path starts with slash or it doesn't. Get rid of the "/?" in the RewriteRule pattern and replace it with just "/" or blank.

If *all* requests to the redirected domains are to be redirected, then you only need one rule.

Or if *all* of the articles share some common 'words' or a common format (say they contain one or more hyphens), then again, you may need only one rule. Make the most of regular-expressions pattern-matching to reduce the number of rules if possible.

Be aware that as coded, requests referred from non-www "articledirectory" sites will not be redirected. Be sure you have hostname canonicalization rules in place on those domains, or alternately, modify the patterns above to accept non-www referrals -- ^www.articledirectory.com/?article1$ becomes ^(www\.)?articledirectory\.com/?article1$

Jim