httpd-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Hans Juergen von Lengerke <lenger...@sixt.de>
Subject Re: [users@httpd] RewriteRule with [R,E] flags
Date Wed, 28 Aug 2002 12:59:18 GMT
Evgeny Chuykov <gecka@baik.ru> on Aug 28, 2002:

> Is it possible to set environment variable and make redirect in
> the RewriteRule directive?
>
> I've tried something like this:
>
> RewriteRule ^(.*)foo.php$ bar.php [L,R,E=X:$1]
>
> It redirects but looses environment variable.
> Any workarounds?

This works fine, but it doesn't do what you want because when you
redirect, the client will issue a new request and in the new request you
won't have your environment variable set. The environment variable was
only set for the request that has been finished by sending the client
the redirect to bar.php.


Workarounds: either don't use [R] but redirect internally:

   RewriteRule ^(.*)foo.php$ bar.php [L,E=X:$1]

or pass some additional query arguments to bar.php:

   RewriteRule ^(.*)foo.php$ bar.php?X=$1 [L,R,QSA]

or pass these arguments somehow in the URL, although this is more or
less the same thing as the first suggestion, just more complicated :)

   RewriteRule ^(.*)foo.php$   /X/$1/bar.php [L,R]
   RewriteRule ^/X/.*/bar.php$ bar.php [L,E=X:$1]


None of these rules are tested for syntactic correctness, but you should
be able to get any of them working. Did you have a look at the rewrite
guide?


---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Mime
View raw message