You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Christopher Fox <ch...@EDGETRADE.com> on 2001/04/18 03:15:20 UTC
pulling arguments off rewrite rule
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 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
my boss wants me to do this in JSP and I am trying to defy him
as i have told him mod perl is waaaaaaaaaay better
thanks,
Chris
Re: pulling arguments off rewrite rule
Posted by Erdmut Pfeifer <e....@science-computing.de>.
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! --