Question : nginx - possible to rewrite based on referring url?

here is an example called url:
http://myserver.com/index.php?id=15

I would like to change the id= based on referrer....

so I will have a list of referers....

if referer url contains moo/cow.php then rewrite to:
http://myserver.com/index.php?id=15

if referer url contains milk/cookies.php then rewrite to:
http://myserver.com/index.php?id=16

Thanks,

-Eric

Answer : nginx - possible to rewrite based on referring url?

Hi first thing, if your expecting this rule to fire when the user requests page "/moo/dog.html?id=99" then you need to change the  rewrite ^.*/index.php  for ^.*/moo/dog.html$, unless there are other rules already in place, that may muddy things.

I'm far from a nginx expert, but am I correct in thinking the $http_HEADER variable contains the full HTTP header, including the referer, so it may be worth switching the two to see if it makes a difference. Also the syntax below may be closer to what you want


if ($http_referer ~* (moo/cow.html) ) {
   set $test  a;
}

if ($args !~* "id=15"){
   set $test  "${test}b";
}

if ($test = ab ) {
     rewrite  ^.*/moo/dog.html$  http://target.electronicgroups.com/moo/cat.html?id=15   last;
}
   
Random Solutions  
 
programming4us programming4us