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

Posted at Nginx Forum: