perl-modperl mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Erdmut Pfeifer <>
Subject Re: pulling arguments off rewrite rule
Date Wed, 18 Apr 2001 13:27:49 GMT
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 
> 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
> I rewrite it to 
> 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:/.../
  RewriteCond   %{QUERY_STRING}  (.*)
  RewriteRule   ^(.*)$           ${rwmap:%1##$1}

  # or alternatively:
  # RewriteRule   ^(.*)$         ${rwmap:%{QUERY_STRING}##$1} for example being:


$| = 1;  # non-buffered IO
while (<>) {
    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 Pfeifer
science+computing ag

-- Bugs come in through open windows. Keep Windows shut! --

View raw message