You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by Nikolai Lusan <ni...@hitwise.com> on 2007/04/23 03:13:30 UTC
[users@httpd] mod_rewrite and environment variables
Greetings all,
I have an issue, I maintain several sites that use the same code base
and are required to be in separate VirtualHosts. These sites all have
"sister" sites (separate code base different functionality) that also
operate out of separate VirtuaHosts. I am trying to redirect things from
one site to another using mod_rewrite ... however to allow us to
maintain things in a consistent state across the sites I would like to
be able to set an environment variable for substitution into the rewrite
rules in a single include file.
Example:
Site "Sister" Site
www.a.com foo.a.com
www.b.com foo.b.com
in VirtaulHost for www.a.com
SetEnv SISTER_SITE foo.a.com
Include common_rewrites.conf
in VirtaulHost for www.b.com
SetEnv SISTER_SITE foo.b.com
Include common_rewrites.conf
Then in common_rewrites.conf
RewriteCond %{REQUEST_FILENAME} ^/bar$
RewriteRule ^.*$ http://%{ENV:SISTER_SITE}/bar [R=permanent,L]
This approach does not seem to work, although the environment variables
can be used in the RewriteCond statement they seem to be ignored in the
RewriteRule statement.
Does anyone have any idea how I can get the functionality I desire?
trying to use Redirect with environment variables returns the same as
rewrite. Is there and existing external rewrite engine I can use? or is
there a better way to get this functionality?
--
Nikolai Lusan
Systems Administrator
Hitwise Pty. Ltd.
Level 7 / 580 St Kilda Road
Melbourne, Victoria 3004
Australia
Phone: +61 3 8530 2400
Fax: +61 3 9529 8907
www.hitwise.com.au
nikolai.lusan@hitwise.com
Worldwide: • United States • United Kingdom • Australia • New
Zealand • Singapore • Hong Kong
To subscribe to our complimentary monthly newsletter, visit:
http://www.hitwise.com.au/
The information transmitted may be confidential, is intended only for
the person to which it is addressed, and may not be reviewed,
retransmitted, disseminated or relied upon by any other persons. If you
received this message in error, please contact the sender and destroy
any paper or electronic copies of this message. Any views expressed in
this email communication are those of the individual sender, except
where the sender specifically states otherwise. Hitwise does not
represent, warrant or guarantee that the communication is free of
errors, virus or interference.
---------------------------------------------------------------------
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 and environment variables
Posted by Nikolai Lusan <ni...@hitwise.com>.
Hey,
For anyone interested I have solved this one.
Instead of using SetEnv I am doing a catch all match after enabling the
rewrite engine in each vhost:
RewriteEngine On
RewriteRule ^(.*)$ $1 [E=SISTER_SITE:foo.a.com]
Then in the conf file for the rewrites i do the matches as:
RewriteCond %{REQUEST_FILENAME} ^/bar$
RewriteCond %{ENV:SISTER_SITE} (.*)
RewriteRule ^.*$ http://%1/bar [R=permanent,L]
On Mon, 2007-04-23 at 11:13 +1000, Nikolai Lusan wrote:
> Example:
>
> Site "Sister" Site
> www.a.com foo.a.com
> www.b.com foo.b.com
>
> in VirtaulHost for www.a.com
>
> SetEnv SISTER_SITE foo.a.com
> Include common_rewrites.conf
>
> in VirtaulHost for www.b.com
>
> SetEnv SISTER_SITE foo.b.com
> Include common_rewrites.conf
>
> Then in common_rewrites.conf
>
> RewriteCond %{REQUEST_FILENAME} ^/bar$
> RewriteRule ^.*$ http://%{ENV:SISTER_SITE}/bar [R=permanent,L]
>
>
> This approach does not seem to work, although the environment variables
> can be used in the RewriteCond statement they seem to be ignored in the
> RewriteRule statement.
--
Nikolai Lusan
Systems Administrator
Hitwise Pty. Ltd.
Level 7 / 580 St Kilda Road
Melbourne, Victoria 3004
Australia
Phone: +61 3 8530 2400
Fax: +61 3 9529 8907
www.hitwise.com.au
nikolai.lusan@hitwise.com
Worldwide: • United States • United Kingdom • Australia • New
Zealand • Singapore • Hong Kong
To subscribe to our complimentary monthly newsletter, visit:
http://www.hitwise.com.au/
The information transmitted may be confidential, is intended only for
the person to which it is addressed, and may not be reviewed,
retransmitted, disseminated or relied upon by any other persons. If you
received this message in error, please contact the sender and destroy
any paper or electronic copies of this message. Any views expressed in
this email communication are those of the individual sender, except
where the sender specifically states otherwise. Hitwise does not
represent, warrant or guarantee that the communication is free of
errors, virus or interference.
---------------------------------------------------------------------
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