How to redirect affiliate link and add tracking code?
I have an WordPress website. There is an affiliate link on home page. I redirect (cloak) this link with .htaccess
Redirect:
Redirect 302 /go/besthost https://www.affiliatepanel.com/?id=12345
My website is on example.com
.
Running ads I send URL Parameters
https://www.example.com?ad=adname&camp=cname&source=google
How to read URL parameters and add them to affiliate link so it should become
https://www.affiliatepanel.com/?id=12345&ad=adname&camp=cname&source=google
In order to pass the URL parameters you'll need to use a mod_rewrite RewriteRule
(redirect), rather than a mod_alias Redirect
directive.
For example, if the request is https://www.example.com/url-path?url-parameters
and you want to redirect this to https://www.affiliatepanel.com/?id=12345&url-parameters
then you would do something like the following using mod_rewrite at the top of your .htaccess
file:
RewriteEngine On
RewriteRule ^url-path$ https://www.affiliatepanel.com/?id=12345 [QSA,R=302,L]
The QSA
flag (Query string Append) does the "magic" of appending the original query string (ie. "url-parameters") from the request on to the redirected URL.
If it wasn't for the fact you are adding a new query string (ie. id=12345
) then you wouldn't have to do anything, since the query string is appended by default (as long as you don't add a new one).
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.