You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by Thorsten Scherler <th...@juntadeandalucia.es> on 2008/03/11 08:37:12 UTC
Re: [users@httpd] How to set environment variable from RewriteMap?
(was Re: [users@httpd] mod_rewrite E flag does not set env. variable)
On Mon, 2008-03-10 at 14:01 +0100, Krist van Besien wrote:
> On Mon, Mar 10, 2008 at 1:44 PM, Thorsten Scherler
> <th...@juntadeandalucia.es> wrote:
>
> > RewriteMap portadaboja txt:/opt/datos/httpd/redirect.txt
> > SetEnv FOCUS ${portadaboja:boletin}
> >
> > but the variable will the return the literal context. Meaning
> > ${portadaboja:boletin} and not the result of this expression.
>
> That expression will only be evaluated in the context of a RewriteRule
> or a RewriteCond
I thought so, thanks for clarification.
> > Does somebody has an idea how I can save either whether a rewrite had
> > happened or the result of the rewriteMap expression.
>
> If you want to save that information during request processing you can
> use an environment variable, just like you did. If you want to save
> information from one request to another you need another mechanism.
Which mechanism would you suggest?
> However, you are doing the following:
>
> RewriteRule "^/BOJA$"
> "http://%{HTTP_HOST}/boja/${portadaboja:boletin}" [E=FOCUS:true,L]
>
> (now with L as you mentioned, however that makes the
> http://%{HTTP_HOST} completely superfluous)
>
> That means that your SSI processing will happen inside a file whose
> name is the result of the rewrite map. So you know what the result is,
> don't you? You're getting it as part of the URL...
Well, like I said the other mail: "L flag, that is working just fine
however that is not solving my problem, since I depending on a rewrite
of the url."
Thanks very much for explaining.
salu2
--
Thorsten Scherler thorsten.at.apache.org
Open Source Java consulting, training and solutions
---------------------------------------------------------------------
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
Re: [users@httpd] How to set environment variable from RewriteMap?
(was Re: [users@httpd] mod_rewrite E flag does not set env. variable)
Posted by Thorsten Scherler <th...@juntadeandalucia.es>.
On Tue, 2008-03-11 at 14:22 +0100, Thorsten Scherler wrote:
> On Tue, 2008-03-11 at 13:20 +0100, Krist van Besien wrote:
> > On Tue, Mar 11, 2008 at 12:29 PM, Thorsten Scherler
> > <th...@juntadeandalucia.es> wrote:
...
> > Now, what is not entirely clear is what you are trying to do. You want
> > to look something up in a map and compare it with the requested URL,
> > right?
>
> Totally.
>
> > That is going to be complicated.
>
> hehe, yeah, I started to notice. ;)
> Thanks for sticking with me.
In the end the solution have been very easy.
In my very last match I needed to implement the setting of the
environment variable like follows:
RewriteRule ^(.*) %{DOCUMENT_ROOT}$1 [E=REWRITEMAP_RESULT:
${portadaboja:boletin},L]
Now I can compare the REWRITEMAP_RESULT with the REQUEST_URI in my
SSI. :)
Thank you very much Krist for your help.
salu2
--
Thorsten Scherler thorsten.at.apache.org
Open Source Java consulting, training and solutions
---------------------------------------------------------------------
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
Re: [users@httpd] How to set environment variable from RewriteMap?
(was Re: [users@httpd] mod_rewrite E flag does not set env. variable)
Posted by Thorsten Scherler <th...@juntadeandalucia.es>.
On Tue, 2008-03-11 at 13:20 +0100, Krist van Besien wrote:
> On Tue, Mar 11, 2008 at 12:29 PM, Thorsten Scherler
> <th...@juntadeandalucia.es> wrote:
>
> > To overcome that problem I took your suggestion and combined it like:
> > RewriteCond ${portadaboja:boletin} ^(.+)$
> > RewriteCond %{REQUEST_URI} /%1
> >
> > but that is never got hit.
> >
> > What I actually trying is to compare the REQUEST_URI with the map entry.
> > Is this possible and I am just not using it the right way?
>
> If you are trying complicated things with rewrite rules it always is a
> good idea to have a rewritelog, with a high enough loglevel. this will
> show you a lot of what is happening.
I have
RewriteLogLevel 3
> Now, what is not entirely clear is what you are trying to do. You want
> to look something up in a map and compare it with the requested URL,
> right?
Totally.
> That is going to be complicated.
hehe, yeah, I started to notice. ;)
Thanks for sticking with me.
> In the example you gave above,
> are you just using RewriteCond's ?
Yeah, the next line is
RewriteRule ^(.*) %{DOCUMENT_ROOT}$1
[E=FOCUS:true,E=REWRITEMAP_RESULT:%1,L]
> You are aware that a "RewriteCond"
> statement only gets evaluated if the following RewriteRule matches?
Ah, I thought it is the other way around.
> Can you maybe just describe what it is you are trying to achieve?
> Maybe there is a simpler way.
I really hope there is. ;)
I am creating the new version of http://andaluciajunta.es/BOJA. The
current version is a dynamic J2EE app and the next version is completely
based on static html pages (generated by Apache Forrest) that are using
some ssi for common parts.
The common parts are:
- header
- footer
- left menu
Now the left menu will be changed in the new version to just a couple of
points. The most important for our use case are:
- Último boletín (last bulletin)
- Boletines anteriores (older bulletins)
The interesting code snippet is the following:
<li>
<a accesskey="U" href="/BOJA">Último boletín</a>
</li>
<li>
<a accesskey="F" class="actual"
href="/boja/boletines/index.html">Boletines anteriores</a>
</li>
You see the second li has a class="actual" that produces a
presentational highlight. Now all bulletins share the same left.ssi.html
but the last (most recent) bulletin should highlight the first li and
not the second.
The most recent bulletin is defined a redirect.txt that is changed with
every new bulletin (will be generated each day). To prevent to generate
two different ssi for the left menu I wanted to use something like:
<!--#if expr="test_condition" -->
<!--#else -->
<!--#endif -->
to either highlight the first or the second.
Like you noticed I am trying to compare the REQUEST_URI with the result
of the map entry ${portadaboja:boletin}. If they are the same I would
like to set FOCUS=true (where FOCUS=test_condition).
We started with that the R flag which I need to use since the trigger
url (.../BOJA) HAS TO be rewritten to the latest bulletin
(e.g. /boletines/2008/1/index.html) will produce another request.
Now I am trying to compare the requested url with the one from the
rewriteMap to decide which points needs to be highlighted.
Hopes that makes the use case and the requisition clearer.
salu2
--
Thorsten Scherler thorsten.at.apache.org
Open Source Java consulting, training and solutions
---------------------------------------------------------------------
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
Re: [users@httpd] How to set environment variable from RewriteMap? (was Re: [users@httpd] mod_rewrite E flag does not set env. variable)
Posted by Krist van Besien <kr...@gmail.com>.
On Tue, Mar 11, 2008 at 12:29 PM, Thorsten Scherler
<th...@juntadeandalucia.es> wrote:
> To overcome that problem I took your suggestion and combined it like:
> RewriteCond ${portadaboja:boletin} ^(.+)$
> RewriteCond %{REQUEST_URI} /%1
>
> but that is never got hit.
>
> What I actually trying is to compare the REQUEST_URI with the map entry.
> Is this possible and I am just not using it the right way?
If you are trying complicated things with rewrite rules it always is a
good idea to have a rewritelog, with a high enough loglevel. this will
show you a lot of what is happening.
Now, what is not entirely clear is what you are trying to do. You want
to look something up in a map and compare it with the requested URL,
right? That is going to be complicated. In the example you gave above,
are you just using RewriteCond's ? You are aware that a "RewriteCond"
statement only gets evaluated if the following RewriteRule matches?
Can you maybe just describe what it is you are trying to achieve?
Maybe there is a simpler way.
Krist
--
krist.vanbesien@gmail.com
krist@vanbesien.org
Bremgarten b. Bern, Switzerland
--
A: It reverses the normal flow of conversation.
Q: What's wrong with top-posting?
A: Top-posting.
Q: What's the biggest scourge on plain text email discussions?
---------------------------------------------------------------------
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
Re: [users@httpd] How to set environment variable from RewriteMap?
(was Re: [users@httpd] mod_rewrite E flag does not set env. variable)
Posted by Thorsten Scherler <th...@juntadeandalucia.es>.
On Tue, 2008-03-11 at 09:04 +0100, Krist van Besien wrote:
> On Tue, Mar 11, 2008 at 8:37 AM, Thorsten Scherler
> <th...@juntadeandalucia.es> wrote:
> > On Mon, 2008-03-10 at 14:01 +0100, Krist van Besien wrote:
>
> > > If you want to save that information during request processing you can
> > > use an environment variable, just like you did. If you want to save
> > > information from one request to another you need another mechanism.
> >
> > Which mechanism would you suggest?
>
> Two mechanisms are common for persistence across requests: Cookies,
> and query parameters.
I played around with your suggestions and I am nearly there.
# 1.)
RewriteCond %{REQUEST_URI} ^/boletines/2008/1(.*)
# 2.)
RewriteCond %{REQUEST_URI} ^/${portadaboja:boletin}
One is working fine but it is hardcoded (I did it to test). The 2) is
not working because it seems that ${portadaboja:boletin} is not resolved
if used on the "right" site.
To overcome that problem I took your suggestion and combined it like:
RewriteCond ${portadaboja:boletin} ^(.+)$
RewriteCond %{REQUEST_URI} /%1
but that is never got hit.
What I actually trying is to compare the REQUEST_URI with the map entry.
Is this possible and I am just not using it the right way?
salu2
--
Thorsten Scherler thorsten.at.apache.org
Open Source Java consulting, training and solutions
---------------------------------------------------------------------
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
Re: [users@httpd] How to set environment variable from RewriteMap? (was Re: [users@httpd] mod_rewrite E flag does not set env. variable)
Posted by Krist van Besien <kr...@gmail.com>.
On Tue, Mar 11, 2008 at 8:37 AM, Thorsten Scherler
<th...@juntadeandalucia.es> wrote:
> On Mon, 2008-03-10 at 14:01 +0100, Krist van Besien wrote:
> > If you want to save that information during request processing you can
> > use an environment variable, just like you did. If you want to save
> > information from one request to another you need another mechanism.
>
> Which mechanism would you suggest?
Two mechanisms are common for persistence across requests: Cookies,
and query parameters.
Krist
--
krist.vanbesien@gmail.com
krist@vanbesien.org
Bremgarten b. Bern, Switzerland
--
A: It reverses the normal flow of conversation.
Q: What's wrong with top-posting?
A: Top-posting.
Q: What's the biggest scourge on plain text email discussions?
---------------------------------------------------------------------
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