Forum Moderators: phranque
What I'd like to do is to do a 301 redirect for domain.com/index.php?ref=XYZ to domain.com, and set a cookie containing the info "XYZ".
The reason for this is that I have affiliates linking to me (therefore I need to track the "ref" bit...), and I'd like to keep all the "link juice" that comes with their links.
I'm sure this is easy, but unfortunately htaccess isn't my strongest skill. Ideas on how to achieve this?
If you're on Apache 1.x, you can use Apache mod_headers to set the cookie, and a <FilesMatch> container to make it conditional upon a particular filename. Notice that I said filename, not URL, so be careful here.
Seesion Cookie example:
<FilesMatch "^mobileset\.html$">
Header set Set-Cookie: "mobile; path=/; domain=example.com"
</FilesMatch>
You can test cookies in mod_rewrite on Apache 1.3.x and later.
Jim
[edited by: jdMorgan at 3:10 pm (utc) on July 9, 2008]
Can I maybe do a rewrite so that it appears that any requested page on my domain with "?ref=XYZ" is redirected to the same page, but without "?ref=XYZ", flag 301, but still serving the page with the variable (ref=XYZ) intact for my script to use? If this variable is available to my script, then I can always set the cookie through my script.
Is this possible, or have I misunderstood something?
If possible, how would I do that?
It seems this works just fine:
if (isset($_GET['ref'])){
setcookie ($c_name,$c_value,$c_expire,$c_path,$c_domain);
header("HTTP/1.1 301 Moved Permanently");
header("Location: http://www.example.com".$_SERVER['PHP_SELF']);
} Thanks a lot for pointing this out to me.
[edited by: jdMorgan at 3:04 pm (utc) on July 12, 2008]
[edit reason] example.com [/edit]