Return-Path: Delivered-To: apmail-modperl-archive@apache.org Received: (qmail 59616 invoked by uid 500); 18 Apr 2001 13:39:04 -0000 Mailing-List: contact modperl-help@apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: list-post: Delivered-To: mailing list modperl@apache.org Received: (qmail 59578 invoked from network); 18 Apr 2001 13:39:04 -0000 Message-ID: <785C904D2CFB7D498A221E6F5B2138C7E2A5F2@PADS.EDGETRADE.com> From: Christopher Fox To: 'Erdmut Pfeifer' , modperl@apache.org Subject: RE: pulling arguments off rewrite rule Date: Wed, 18 Apr 2001 09:38:55 -0400 MIME-Version: 1.0 X-Mailer: Internet Mail Service (5.5.2650.21) Content-Type: text/plain; charset="iso-8859-1" X-Spam-Rating: h31.sny.collab.net 1.6.2 0/1000/N Hi Erdmut, Yes ... basically we want to track which company sent us the reference when customers subscribe. the ref=xxx where xxx will = some company id I want to tack this on to every click so that when the user finally submits an application we can credit the company that gave us the customer I will try your solution and thanks for your thoughts I appreciate it. I could not find much documentation regarding this issue. Chris -----Original Message----- From: Erdmut Pfeifer [mailto:e.pfeifer@science-computing.de] Sent: Wednesday, April 18, 2001 9:28 AM To: modperl@apache.org Subject: Re: pulling arguments off rewrite rule On Tue, Apr 17, 2001 at 09:15:20PM -0400, Christopher Fox wrote: > I am trying to get the arguments from a referrer off a rewrite rule > > here's the deal: > > I have a request coming in > > http://www.blah.com/index.htm?ref=xxx > > I want to pull the ref=xxx and have it follow the user throughout my site I'm afraid I'm not quite sure what you mean by "have it follow ... throughout ...". Do you intend to implement a kind of session management this way? > I am using a RewriteMap to a program and want to return the QUERY_STRING > when rewriting the url > > so when a user clicks the next page > > http://www.blah.com/next.htm > > I rewrite it to > > http://www.blah.com/next.htm?ref=xxx > > > unfortunately the RewriteMap program is not recognizing the QUERY_STRING and > returning null > (i can return a static string no problem) > > > this must be a trivial issue but I am banging my head it's not as trivial as it might seem, but to get hold of the query string from within your rewrite map program you could use something like the following as a workaround: RewriteEngine On RewriteMap rwmap prg:/.../rewritemap.pl RewriteCond %{QUERY_STRING} (.*) RewriteRule ^(.*)$ ${rwmap:%1##$1} # or alternatively: # RewriteRule ^(.*)$ ${rwmap:%{QUERY_STRING}##$1} rewritemap.pl for example being: #!/usr/bin/perl $| = 1; # non-buffered IO while (<>) { chomp; my ($query, $url) = split(/##/, $_, 2); # for demonstration purposes this changes the query string # to an uppercase version it... # (do whatever you need to do here) print "$url?\U$query\n"; } The problem basically is that the rewrite map gets started once together with apache, and its environment is more or less static. Even attempts to set the QUERY_STRING using the RewriteRule-flag 'E=var:val' have no effect on the environment of the rewrite map script. So the workaround is to somehow embed the query string into the string that's being passed to the map, and split it off there. The seperator "##" is more or less arbitrary, but you should of course make sure that it doesn't appear anywhare in the query string itself (although a simple " " (space) would generally be a reasonable choice, this causes syntactic problems specifying it in the RewriteRule -- I haven't yet worked out a way to quote/escape it appropriately). The above scheme could easily be adapted to various purposes, however, I'm not quite sure what you want to achieve ultimately. Specifically, I don't understand who is going to decide which "ref=xxx" string to append if a request comes in without one... but I guess you know what are doing ;) Good luck, Erdmut -- Erdmut Pfeifer science+computing ag -- Bugs come in through open windows. Keep Windows shut! --