You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by "A. K." <ak...@gmail.com> on 2006/11/30 16:52:05 UTC

[users@httpd] mod_rewrite: remembering environment variables

The mod_rewrite doc mentions that the *E=**VAR*:*VAL flag *"[can be used] to
strip but remember information from URLs".

What exactly does that mean?

I need to "remember" the values of certain EV's after a rewrite process has
completed. It would be particluarly useful to me know what the original
HTTP_HOST was as requests come through for content referenced by relative
paths on the original host but the HTTP_HOST has already been rewritten.

Could I use SetEnv to create an EV called ORIGINAL_HOST and then set it to
the value of HTTP_HOST prior to rewrites so that I can reference it during
subsequent rewrites?

What would be the best method for accomplishing this? Or am I totally off
the mark regarding what SetEnv and *E=**VAR*:*VAL *do?

Any and all help, suggestions, appreciated.

Re: [users@httpd] mod_rewrite: remembering environment variables

Posted by "A. K." <ak...@gmail.com>.
Joshua,

First of all, thanks for your responses. I've never had to "configure"
apache at all prior to this exercise so I'm fairly green in that regard. No
better place to start than mod_proxy and mod_rewrite, huh?

Anyways ....proxy server, yes. However, I can't use a real proxy because
filtering does not satisfy my requirements. The request needs to be
rewritten to the localhost script so it can be returned to the client as
part of an HTML frameset. For instance, a request for google.com gets
displayed in the browser as part of an HTML frameset with the original
request for google being just one of the frames and otherwise unaltered.
More stuff happens than just that in the script but the framing is the main
point.

BTW, I guess I was using HTTP_HOST and SERVER_NAME interchangeably. Sorry
for the confusion, I wasn't expecting them to be different.

So I guess the question would be, is there a way to do this with just
mod_proxy, mod_rewrite and a Perl script? Or ...do I have to cobble
something from scratch in C and not use apache at all?

On 11/30/06, Joshua Slive <jo...@slive.ca> wrote:
>
> On 11/30/06, A. K. <ak...@gmail.com> wrote:
> > iptables redirects to the VirtualHost which rewrites to the script
> housed on
> > localhost. The script does some processing then "re-requests" the
> original
> > request based on the parameters and query string passed to it.
> >
> > google.com will display just fine except for the logo image which gets
> > re-written to http://10.0.255.1/intl/en_ALL/images/logo.gif
> >
> > If I add a third rule, "RewriteRule (.*) http://www.google.com$1 [P]",
> the
> > image is fetched appropriately. The question is how do I dynamically
> > determine what the appropriate HTTP_HOST should be?
> >
> > Is my approach "fixable"? Or should I be attacking this differently?
>
> Seems crazy to me.  I guess you are using this as a proxy server?  Why
> not use a real proxy with some filtering (if necessary) to make any
> changes to want.
>
> And I don't understand your setup because you seem to imply that there
> is a difference between SERVER_NAME and HTTP_HOST.  Why is that the
> case?  The SERVER_NAME is already passed in the request, so why not
> use that?
>
> Anyway, back to your original question, environment variables won't do
> you any good because you are using external redirects.  That means an
> entirely new request will be created with entirely new environment
> variables.  If you really need to pass the HTTP_HOST, then pass it in
> the query string as you are doing with SERVER_NAME.
>
> Joshua.
>
> ---------------------------------------------------------------------
> 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] mod_rewrite: remembering environment variables

Posted by Joshua Slive <jo...@slive.ca>.
On 11/30/06, A. K. <ak...@gmail.com> wrote:
> iptables redirects to the VirtualHost which rewrites to the script housed on
> localhost. The script does some processing then "re-requests" the original
> request based on the parameters and query string passed to it.
>
> google.com will display just fine except for the logo image which gets
> re-written to http://10.0.255.1/intl/en_ALL/images/logo.gif
>
> If I add a third rule, "RewriteRule (.*) http://www.google.com$1 [P]", the
> image is fetched appropriately. The question is how do I dynamically
> determine what the appropriate HTTP_HOST should be?
>
> Is my approach "fixable"? Or should I be attacking this differently?

Seems crazy to me.  I guess you are using this as a proxy server?  Why
not use a real proxy with some filtering (if necessary) to make any
changes to want.

And I don't understand your setup because you seem to imply that there
is a difference between SERVER_NAME and HTTP_HOST.  Why is that the
case?  The SERVER_NAME is already passed in the request, so why not
use that?

Anyway, back to your original question, environment variables won't do
you any good because you are using external redirects.  That means an
entirely new request will be created with entirely new environment
variables.  If you really need to pass the HTTP_HOST, then pass it in
the query string as you are doing with SERVER_NAME.

Joshua.

---------------------------------------------------------------------
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] mod_rewrite: remembering environment variables

Posted by "A. K." <ak...@gmail.com>.
iptables redirects to the VirtualHost which rewrites to the script housed on
localhost. The script does some processing then "re-requests" the original
request based on the parameters and query string passed to it.

google.com will display just fine except for the logo image which gets
re-written to http://10.0.255.1/intl/en_ALL/images/logo.gif

If I add a third rule, "RewriteRule (.*) http://www.google.com$1 [P]", the
image is fetched appropriately. The question is how do I dynamically
determine what the appropriate HTTP_HOST should be?

Is my approach "fixable"? Or should I be attacking this differently?

Listen *:10000
<VirtualHost *:10000>
    RewriteEngine on
    RewriteCond %{SERVER_NAME}          !^10\.0\.255\.1$
    RewriteRule (.*)                                 "
http://10.0.255.1/cgi-bin/script.pl?%{SERVER_NAME}%{REQUEST_URI}&"
[QSA,L]
    RewriteCond %{REQUEST_URI}            !script\.pl
    RewriteRule ^/cgi-bin/(.*)$         "http://$1?" [P]
</VirtualHost>
ProxyRequests On
<Proxy *>
 Order deny,allow
 Deny from all
 Allow from 10.0.255.0/24
</Proxy>


On 11/30/06, Joshua Slive <jo...@slive.ca> wrote:
>
> On 11/30/06, A. K. <ak...@gmail.com> wrote:
> > The mod_rewrite doc mentions that the E=VAR:VAL flag "[can be used] to
> strip
> > but remember information from URLs".
> >
> > What exactly does that mean?
> >
> > I need to "remember" the values of certain EV's after a rewrite process
> has
> > completed. It would be particluarly useful to me know what the original
> > HTTP_HOST was as requests come through for content referenced by
> relative
> > paths on the original host but the HTTP_HOST has already been rewritten.
> >
> > Could I use SetEnv to create an EV called ORIGINAL_HOST and then set it
> to
> > the value of HTTP_HOST prior to rewrites so that I can reference it
> during
> > subsequent rewrites?
> >
> > What would be the best method for accomplishing this? Or am I totally
> off
> > the mark regarding what SetEnv and E=VAR:VAL do?
>
> You need to provide some details on your configuration, because the
> answer changes depending on whether you are using internal rewriting
> (aliasing), external rewriting (redirecting) or proxying.
>
> Joshua.
>
> ---------------------------------------------------------------------
> 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] mod_rewrite: remembering environment variables

Posted by Joshua Slive <jo...@slive.ca>.
On 11/30/06, A. K. <ak...@gmail.com> wrote:
> The mod_rewrite doc mentions that the E=VAR:VAL flag "[can be used] to strip
> but remember information from URLs".
>
> What exactly does that mean?
>
> I need to "remember" the values of certain EV's after a rewrite process has
> completed. It would be particluarly useful to me know what the original
> HTTP_HOST was as requests come through for content referenced by relative
> paths on the original host but the HTTP_HOST has already been rewritten.
>
> Could I use SetEnv to create an EV called ORIGINAL_HOST and then set it to
> the value of HTTP_HOST prior to rewrites so that I can reference it during
> subsequent rewrites?
>
> What would be the best method for accomplishing this? Or am I totally off
> the mark regarding what SetEnv and E=VAR:VAL do?

You need to provide some details on your configuration, because the
answer changes depending on whether you are using internal rewriting
(aliasing), external rewriting (redirecting) or proxying.

Joshua.

---------------------------------------------------------------------
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