You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by Avi Mozes <am...@hotmail.com> on 2004/01/31 10:55:25 UTC

[users@httpd] mod_rewrite with dynamic mirrors

Hi all,
new to apache's mod_rewrite.  I have a situation and was wondering if Apache 
could do it.
I have two sites: site1.com and site2.com.
site1.com is complete and it's files are located in /home/site1/
site2.com wants to go off of site1.com's files.
With a dynamic mirror on site2 (RewriteRule    ^(.*)$  
http://www.site1.com/$1  [P]), I can make it look like site2.com is 
site1.com.
The only issue I have is, is there a way of making it so site1.com shows 
site2.com always in the URL bar.
So, for example, a user goes to www.site2.com, they get www.site1.com's 
content.
And if a user goes to www.site1.com, they get www.site1.com's content, but 
in the URL bar it shows www.site2.com at all times.

Any ideas?  And if there's a better way than a dynamic mirror to solve half 
the problem (as I already did), please let me know.  Thanks more all your 
help in advance!

Avi
amozes@hotmail.com

_________________________________________________________________
What are the 5 hot job markets for 2004? Click here to find out. 
http://msn.careerbuilder.com/Custom/MSN/CareerAdvice/WPI_WhereWillWeFindJobsIn2004.htm?siteid=CBMSN3006&sc_extcmp=JS_wi08_dec03_hotmail1


---------------------------------------------------------------------
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] Help me please .. Mod_rewrite

Posted by Brian Dessent <br...@dessent.net>.
Jerome Schevingt wrote:
> 
> Very thanks Brian, that's work very good ...
> 
> Another question if possible ;=)
> 
> Do you know if i add a Login/Password protection based on mysql table ?
> 
> Ex:
> 
> http://stats.nightrain.com/clients/www.toto.com
> require a authentification L/P based on a MySQL Table where
> url="www.toto.com"
> 
> http://stats.nightrain.com/clients/www.tata.com
> require a authentification L/P based on a MySQL Table where url=www.tata.com

I believe that mod_rewrite intercepts the handling of the URLs before
authentication is done.  So, the following may not work at all, I really
don't know.

Inside the stats vhost:

<Location /clients/www.toto.com>
   AuthType Basic
   AuthName "Stats Login"
   Require user www.toto.com
</Location>

<Location /clients/www.tata.com>
   AuthType Basic
   AuthName "Stats Login"
   Require user www.tata.com
</Location>

...etc...

Then also install mod_auth_mysql <http://modauthmysql.sourceforge.net/>
and provide the name of the DB, name of the table, MySQL login name,
etc. in the global server context.  You may instead have to repeat these
AuthMySQL parameters inside each Location container, I don't know.

I know of no way to have this done automatically for any possible
hostname under /clients/.  But, you could write a perl script that
generates those <Location> containers (based on a list of domains, or
from all the names in the MySQL table) prior to starting the server. 
You could then use 'Include' to read in that output so that the perl
program needn't touch httpd.conf.  If you add or remove a domain while
the server is running then you'd just rerun the perlscript and execute
"apachectl graceful".

It's not a particularly billiant solution, if it even works.  There
might be a better way lurking out there, though.

Brian

---------------------------------------------------------------------
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] Help me please .. Mod_rewrite

Posted by Jerome Schevingt <li...@nightrain.com>.
Very thanks Brian, that's work very good ...

Another question if possible ;=)

Do you know if i add a Login/Password protection based on mysql table ?

Ex:

http://stats.nightrain.com/clients/www.toto.com
require a authentification L/P based on a MySQL Table where
url="www.toto.com"

http://stats.nightrain.com/clients/www.tata.com
require a authentification L/P based on a MySQL Table where url=www.tata.com

Thanks for your help







----- Original Message ----- 
From: "Brian Dessent" <br...@dessent.net>
To: <us...@httpd.apache.org>
Sent: Monday, February 02, 2004 3:18 PM
Subject: Re: [users@httpd] Help me please .. Mod_rewrite


Jerome Schevingt wrote:

> 81.166.22.29 - - [02/fév/2004:13:04:35 +0100]
> [stats.nightrain.com/sid#8120ae0][rid#8fc74f0/initial] (2) init rewrite
> engine with requested uri /clients/www.toto.com
> 81.166.22.29 - - [02/fév/2004:13:04:35 +0100]
> [stats.nightrain.com/sid#8120ae0][rid#8fc74f0/initial] (3) applying
pattern
> '^/clients/(.+)$' to uri '/clients/www.toto.com'
> 81.166.22.29 - - [02/fév/2004:13:04:35 +0100]
> [stats.nightrain.com/sid#8120ae0][rid#8fc74f0/initial] (2) rewrite
> /clients/www.toto.com ->
> http://www-srv1.nightrain.com/cgi-bin/awstats.pl?config=www.toto.com
> 81.166.22.29 - - [02/fév/2004:13:04:35 +0100]
> [stats.nightrain.com/sid#8120ae0][rid#8fc74f0/initial] (3) split
>
uri=http://www-srv1.nightrain.com/cgi-bin/awstats.pl?config=www.toto.com ->
> uri=http://www-srv1.nightrain.com/cgi-bin/awstats.pl,
> args=config=www.toto.com
> 81.166.22.29 - - [02/fév/2004:13:04:35 +0100]
> [stats.nightrain.com/sid#8120ae0][rid#8fc74f0/initial] (2) forcing
> proxy-throughput with http://www-srv1.nightrain.com/cgi-bin/awstats.pl
> 81.166.22.29 - - [02/fév/2004:13:04:35 +0100]
> [stats.nightrain.com/sid#8120ae0][rid#8fc74f0/initial] (1) go-ahead with
> proxy request proxy:http://www-srv1.nightrain.com/cgi-bin/awstats.pl [OK]

The above is the first request.  It looks fine.  The next request is for
/clients/awstats.pl as you noted, and that's not right.

I think the problem you're having is due to how AWstats works.  It
expects to be able to construct self-referential (relative) URLs.  For
example, if you look at what it returns from loading
"/cgi-bin/awstats.pl?config=foo", it returns a frameset, similar to the
following:

<frameset>
<frame name="mainleft" src="awstats.pl?config=foo&framename=mainleft">
<frame name="mainright" src="awstats.pl?config=foo&framename=mainright">
</frameset>

Additionally, the links within the stats pages are also relative URLs of
the form

<a href="awstats.pl?arg=something">

When the browser tries to load one of these such links, it thinks the
current URL is

http://stats.nightrain.com/clients/www.toto.com

...and so when it sees a relative link such as the above, it tries to
request it as

http://stats.nightrain.com/clients/awstats.pl?arg=something

...because /clients/ is the current directory.  So you need to add a
rule to pass through these calls to awstats.pl, and anything else in
/cgi-bin/ that Awstats would refer to.  Try something like this:

RewriteEngine On
RewriteRule ^/clients/awstats\.pl$ \
   http://www-srv1.nightrain.com/cgi-bin/awstats.pl [P]
RewriteRule ^/clients/([0-9A-Za-z.-]+)$ \
   http://www-srv1.nightrain.com/cgi-bin/awstats.pl?config=$1 [P]

Note that the \ on the end is for readability in email, you'd make those
all on one line in your config.  Also remember that the order of the two
is important, since requests for "/clients/awstats.pl" will match either
line, but you want it handled by the first one.

I changed your regexp a little because it's safer.  If you know that a
domain name must come after /clients/ then have it only match against
valid domain characters.  Otherwise you might accidently open yourself
up to mischief since mod_rewrite will pass on anything after the
"/clients/" part without checking it at all.  In this case it shouldn't
matter since the $1 is being put in the query string and not the URI
part of the request.

Also, if there are any other URLs in the Awstats output (such as image
files) then you will also have to make provisions to reverse-proxy them
as well.  For example, if the Awstats output contains things such as:

<img src="/images/awstats/something.png">

Then you will need to do something like the following in your
stats.nightrain.com virtualhost:

ProxyPass /images/awstats/ \
    http://www-srv1.nightrain.com/images/awstats/
ProxyPassReverse /images/awstats/ \
    http://www-srv1.nightrain.com/images/awstats/

ProxyPass is more or less the same as using mod_rewrite with the [P],
except that it should be slightly more efficient if you are mirroring
paths or subdirectories without changing the layout.  ProxyPassReverse
is good to use also since it will rewrite any URLs in the Location field
if a Redirect is used by the site being proxied.  In the case of images
it's probably not necessary.

Alternatively, you could copy over the images into the docroot of the
stats vhost and not bother proxying them.

Brian

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



---------------------------------------------------------------------
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] Help me please .. Mod_rewrite

Posted by Brian Dessent <br...@dessent.net>.
Jerome Schevingt wrote:

> 81.166.22.29 - - [02/fév/2004:13:04:35 +0100]
> [stats.nightrain.com/sid#8120ae0][rid#8fc74f0/initial] (2) init rewrite
> engine with requested uri /clients/www.toto.com
> 81.166.22.29 - - [02/fév/2004:13:04:35 +0100]
> [stats.nightrain.com/sid#8120ae0][rid#8fc74f0/initial] (3) applying pattern
> '^/clients/(.+)$' to uri '/clients/www.toto.com'
> 81.166.22.29 - - [02/fév/2004:13:04:35 +0100]
> [stats.nightrain.com/sid#8120ae0][rid#8fc74f0/initial] (2) rewrite
> /clients/www.toto.com ->
> http://www-srv1.nightrain.com/cgi-bin/awstats.pl?config=www.toto.com
> 81.166.22.29 - - [02/fév/2004:13:04:35 +0100]
> [stats.nightrain.com/sid#8120ae0][rid#8fc74f0/initial] (3) split
> uri=http://www-srv1.nightrain.com/cgi-bin/awstats.pl?config=www.toto.com ->
> uri=http://www-srv1.nightrain.com/cgi-bin/awstats.pl,
> args=config=www.toto.com
> 81.166.22.29 - - [02/fév/2004:13:04:35 +0100]
> [stats.nightrain.com/sid#8120ae0][rid#8fc74f0/initial] (2) forcing
> proxy-throughput with http://www-srv1.nightrain.com/cgi-bin/awstats.pl
> 81.166.22.29 - - [02/fév/2004:13:04:35 +0100]
> [stats.nightrain.com/sid#8120ae0][rid#8fc74f0/initial] (1) go-ahead with
> proxy request proxy:http://www-srv1.nightrain.com/cgi-bin/awstats.pl [OK]

The above is the first request.  It looks fine.  The next request is for
/clients/awstats.pl as you noted, and that's not right.

I think the problem you're having is due to how AWstats works.  It
expects to be able to construct self-referential (relative) URLs.  For
example, if you look at what it returns from loading
"/cgi-bin/awstats.pl?config=foo", it returns a frameset, similar to the
following:

<frameset>
<frame name="mainleft" src="awstats.pl?config=foo&framename=mainleft">
<frame name="mainright" src="awstats.pl?config=foo&framename=mainright">
</frameset>

Additionally, the links within the stats pages are also relative URLs of
the form

<a href="awstats.pl?arg=something">

When the browser tries to load one of these such links, it thinks the
current URL is 

http://stats.nightrain.com/clients/www.toto.com

...and so when it sees a relative link such as the above, it tries to
request it as

http://stats.nightrain.com/clients/awstats.pl?arg=something

...because /clients/ is the current directory.  So you need to add a
rule to pass through these calls to awstats.pl, and anything else in
/cgi-bin/ that Awstats would refer to.  Try something like this:

RewriteEngine On
RewriteRule ^/clients/awstats\.pl$ \
   http://www-srv1.nightrain.com/cgi-bin/awstats.pl [P]
RewriteRule ^/clients/([0-9A-Za-z.-]+)$ \
   http://www-srv1.nightrain.com/cgi-bin/awstats.pl?config=$1 [P]

Note that the \ on the end is for readability in email, you'd make those
all on one line in your config.  Also remember that the order of the two
is important, since requests for "/clients/awstats.pl" will match either
line, but you want it handled by the first one.

I changed your regexp a little because it's safer.  If you know that a
domain name must come after /clients/ then have it only match against
valid domain characters.  Otherwise you might accidently open yourself
up to mischief since mod_rewrite will pass on anything after the
"/clients/" part without checking it at all.  In this case it shouldn't
matter since the $1 is being put in the query string and not the URI
part of the request.

Also, if there are any other URLs in the Awstats output (such as image
files) then you will also have to make provisions to reverse-proxy them
as well.  For example, if the Awstats output contains things such as:

<img src="/images/awstats/something.png">

Then you will need to do something like the following in your
stats.nightrain.com virtualhost:

ProxyPass /images/awstats/ \
    http://www-srv1.nightrain.com/images/awstats/
ProxyPassReverse /images/awstats/ \
    http://www-srv1.nightrain.com/images/awstats/

ProxyPass is more or less the same as using mod_rewrite with the [P],
except that it should be slightly more efficient if you are mirroring
paths or subdirectories without changing the layout.  ProxyPassReverse
is good to use also since it will rewrite any URLs in the Location field
if a Redirect is used by the site being proxied.  In the case of images
it's probably not necessary.

Alternatively, you could copy over the images into the docroot of the
stats vhost and not bother proxying them.

Brian

---------------------------------------------------------------------
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] Help me please .. Mod_rewrite

Posted by Jerome Schevingt <li...@nightrain.com>.
Hi

Thanks for your answer ... i have put log file and level 9 debug, delete the
L.
Yes i load mod_proxy.

This is the logs :


81.166.22.29 - - [02/fév/2004:13:04:35 +0100]
[stats.nightrain.com/sid#8120ae0][rid#8fc74f0/initial] (2) init rewrite
engine with requested uri /clients/www.toto.com
81.166.22.29 - - [02/fév/2004:13:04:35 +0100]
[stats.nightrain.com/sid#8120ae0][rid#8fc74f0/initial] (3) applying pattern
'^/clients/(.+)$' to uri '/clients/www.toto.com'
81.166.22.29 - - [02/fév/2004:13:04:35 +0100]
[stats.nightrain.com/sid#8120ae0][rid#8fc74f0/initial] (2) rewrite
/clients/www.toto.com ->
http://www-srv1.nightrain.com/cgi-bin/awstats.pl?config=www.toto.com
81.166.22.29 - - [02/fév/2004:13:04:35 +0100]
[stats.nightrain.com/sid#8120ae0][rid#8fc74f0/initial] (3) split
uri=http://www-srv1.nightrain.com/cgi-bin/awstats.pl?config=www.toto.com ->
uri=http://www-srv1.nightrain.com/cgi-bin/awstats.pl,
args=config=www.toto.com
81.166.22.29 - - [02/fév/2004:13:04:35 +0100]
[stats.nightrain.com/sid#8120ae0][rid#8fc74f0/initial] (2) forcing
proxy-throughput with http://www-srv1.nightrain.com/cgi-bin/awstats.pl
81.166.22.29 - - [02/fév/2004:13:04:35 +0100]
[stats.nightrain.com/sid#8120ae0][rid#8fc74f0/initial] (1) go-ahead with
proxy request proxy:http://www-srv1.nightrain.com/cgi-bin/awstats.pl [OK]
81.166.22.29 - - [02/fév/2004:13:04:36 +0100]
[stats.nightrain.com/sid#8120ae0][rid#8fcf510/initial] (2) init rewrite
engine with requested uri /clients/awstats.pl
81.166.22.29 - - [02/fév/2004:13:04:36 +0100]
[stats.nightrain.com/sid#8120ae0][rid#8fcf510/initial] (3) applying pattern
'^/clients/(.+)$' to uri '/clients/awstats.pl'
81.166.22.29 - - [02/fév/2004:13:04:36 +0100]
[stats.nightrain.com/sid#8120ae0][rid#8fcf510/initial] (2) rewrite
/clients/awstats.pl ->
http://www-srv1.nightrain.com/cgi-bin/awstats.pl?config=awstats.pl
81.166.22.29 - - [02/fév/2004:13:04:36 +0100]
[stats.nightrain.com/sid#8120ae0][rid#8fcf510/initial] (3) split
uri=http://www-srv1.nightrain.com/cgi-bin/awstats.pl?config=awstats.pl ->
uri=http://www-srv1.nightrain.com/cgi-bin/awstats.pl, args=config=awstats.pl
81.166.22.29 - - [02/fév/2004:13:04:36 +0100]
[stats.nightrain.com/sid#8120ae0][rid#8fcf510/initial] (2) forcing
proxy-throughput with http://www-srv1.nightrain.com/cgi-bin/awstats.pl
81.166.22.29 - - [02/fév/2004:13:04:36 +0100]
[stats.nightrain.com/sid#8120ae0][rid#8fcf510/initial] (1) go-ahead with
proxy request proxy:http://www-srv1.nightrain.com/cgi-bin/awstats.pl [OK]
81.166.22.29 - - [02/fév/2004:13:04:36 +0100]
[stats.nightrain.com/sid#8120ae0][rid#8fc74f0/initial] (2) init rewrite
engine with requested uri /clients/awstats.pl
81.166.22.29 - - [02/fév/2004:13:04:36 +0100]
[stats.nightrain.com/sid#8120ae0][rid#8fc74f0/initial] (3) applying pattern
'^/clients/(.+)$' to uri '/clients/awstats.pl'
81.166.22.29 - - [02/fév/2004:13:04:36 +0100]
[stats.nightrain.com/sid#8120ae0][rid#8fc74f0/initial] (2) rewrite
/clients/awstats.pl ->
http://www-srv1.nightrain.com/cgi-bin/awstats.pl?config=awstats.pl
81.166.22.29 - - [02/fév/2004:13:04:36 +0100]
[stats.nightrain.com/sid#8120ae0][rid#8fc74f0/initial] (3) split
uri=http://www-srv1.nightrain.com/cgi-bin/awstats.pl?config=awstats.pl ->
uri=http://www-srv1.nightrain.com/cgi-bin/awstats.pl, args=config=awstats.pl
81.166.22.29 - - [02/fév/2004:13:04:36 +0100]
[stats.nightrain.com/sid#8120ae0][rid#8fc74f0/initial] (2) forcing
proxy-throughput with http://www-srv1.nightrain.com/cgi-bin/awstats.pl
81.166.22.29 - - [02/fév/2004:13:04:36 +0100]
[stats.nightrain.com/sid#8120ae0][rid#8fc74f0/initial] (1) go-ahead with
proxy request proxy:http://www-srv1.nightrain.com/cgi-bin/awstats.pl [OK]



I see that hi start good rewrite :

http://www-srv1.nightrain.com/cgi-bin/awstats.pl?config=www.toto.com

But after, we have :

http://www-srv1.nightrain.com/cgi-bin/awstats.pl?config=awstats.pl

I don't know why he change www.toto.com by awstats.pl ... a idea ?


what is my problems ? this is the split ?

bye





----- Original Message ----- 
From: "Brian Dessent" <br...@dessent.net>
To: <us...@httpd.apache.org>
Sent: Monday, February 02, 2004 11:34 AM
Subject: Re: [users@httpd] Help me please .. Mod_rewrite


> Jerome Schevingt wrote:
>
> > Now, i want the same action but without change URL. I want use Proxy.
> >
> > I put into my VirtualHost:
> >
> >     RewriteEngine On
> >     RewriteRule ^/clients/(.+)$
> > http://www-srv1.nightrain.com/cgi-bin/awstats.pl?config=$1 [P,L]
>
> You don't need 'L' at the end there, it doesn't make any sense when used
> with 'P'.
>
> > When the user put the first url, she don't change (good ..) but the $1
don't
> > work ...
> >
> > My question:
> >     1- He have a debug mode in mod_rewrite ?? for know what is the
problems
>
> Wouldn't it be great if there was a debugging logfile that you could
> enable, and a manual to explain how to turn it on?  :-)
> http://httpd.apache.org/docs/mod/mod_rewrite.html#RewriteLog
>
> >     2- Can i use the good config ?
>
> Explain in more detail what happens or how it fails.  Your config looks
> fine to me.  Make sure you've loaded mod_proxy.
>
> Brian
>
> ---------------------------------------------------------------------
> 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
>
>


---------------------------------------------------------------------
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] Help me please .. Mod_rewrite

Posted by Brian Dessent <br...@dessent.net>.
Jerome Schevingt wrote:

> Now, i want the same action but without change URL. I want use Proxy.
> 
> I put into my VirtualHost:
> 
>     RewriteEngine On
>     RewriteRule ^/clients/(.+)$
> http://www-srv1.nightrain.com/cgi-bin/awstats.pl?config=$1 [P,L]

You don't need 'L' at the end there, it doesn't make any sense when used
with 'P'.

> When the user put the first url, she don't change (good ..) but the $1 don't
> work ...
> 
> My question:
>     1- He have a debug mode in mod_rewrite ?? for know what is the problems

Wouldn't it be great if there was a debugging logfile that you could
enable, and a manual to explain how to turn it on?  :-) 
http://httpd.apache.org/docs/mod/mod_rewrite.html#RewriteLog

>     2- Can i use the good config ?

Explain in more detail what happens or how it fails.  Your config looks
fine to me.  Make sure you've loaded mod_proxy.

Brian

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


[users@httpd] Help me please .. Mod_rewrite

Posted by Jerome Schevingt <li...@nightrain.com>.
Hi

i am new user of apache and i want use mod_rewrite

Actually i have this into my VirtualHost:

    RewriteEngine On
    RewriteRule ^/clients/(.+)$
http://www-srv1.nightrain.com/cgi-bin/awstats.pl?config=$1 [R,L]

When my user put http://stats.nightrain.com/clients/www.toto.com he going
automatiquely
to http://www-srv1.nightrain.com/cgi-bin/awstats.pl?config=www.toto.com
but he see the url http://www-srv1......

Now, i want the same action but without change URL. I want use Proxy.

I put into my VirtualHost:

    RewriteEngine On
    RewriteRule ^/clients/(.+)$
http://www-srv1.nightrain.com/cgi-bin/awstats.pl?config=$1 [P,L]

When the user put the first url, she don't change (good ..) but the $1 don't
work ...

My question:
    1- He have a debug mode in mod_rewrite ?? for know what is the problems
?
    2- Can i use the good config ?

Thanks for your help





---------------------------------------------------------------------
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 with dynamic mirrors

Posted by Brian Dessent <br...@dessent.net>.
Avi Mozes wrote:

> new to apache's mod_rewrite.  I have a situation and was wondering if Apache
> could do it.
> I have two sites: site1.com and site2.com.
> site1.com is complete and it's files are located in /home/site1/
> site2.com wants to go off of site1.com's files.
> With a dynamic mirror on site2 (RewriteRule    ^(.*)$
> http://www.site1.com/$1  [P]), I can make it look like site2.com is
> site1.com.
> The only issue I have is, is there a way of making it so site1.com shows
> site2.com always in the URL bar.
> So, for example, a user goes to www.site2.com, they get www.site1.com's
> content.
> And if a user goes to www.site1.com, they get www.site1.com's content, but
> in the URL bar it shows www.site2.com at all times.
> 
> Any ideas?  And if there's a better way than a dynamic mirror to solve half
> the problem (as I already did), please let me know.  Thanks more all your
> help in advance!

First of all, I'd do this with 'ProxyPass' and 'ProxyPassReverse' rather
than with mod_rewrite.  The most important difference is that with
ProxyPassReverse it will rewrite URLs in the 'Location:' header so that
redirects on the original site work properly on the mirroring one.

As far as what's shown in the URL bar, that's really a client/browser
thing and not an Apache thing.  Most browsers show the site that you're
visiting in the the URL bar, and don't allow you to arbitrarily set it
to anything you want.  If they were to do that, they would be making the
jobs of the credit-card phishers much easier.  They could throw up any
old site on Geocities that purports to be Paypal, and then spam that URL
(sufficiently obfuscated) and hope that suckers will go there and see
"paypal.com" in the URL bar and enter their login and password.

You can use framesets to get around this, but it doesn't really apply in
your case.   If you control the site "example.com", then you can have
that site return just a single frameset that occupies 100% of the
screen.  Inside that frameset you can load any page you want.  But since
it's in a frame the browser displays the URL of the frameset, not of
each individual frame.  So it will say "example.com" all the time,
regardless of what site you load in the frame.  This is a horrible thing
to do, though, as it breaks bookmarks, it breaks navigation, and it
breaks the user-interface.

You could theoretically do what you describe with redirects, assuming
you have control over both sites.  Add a redirect line to site1.com's
config such that all requests are redirected to site2.com:

Redirect / http://site2.com

Now, any accesses to site1.com will be redirected to the same URL on
site2, and this will be reflected in the browser's URL bar since the
person is actually visiting site2.  However, you'll need to make one
exception to that Redirect, for the case of site2.com's server so that
it can mirror (reverse proxy) the site.  Otherwise you'd create a loop,
as when site2 goes to reverse proxy site1 it would be redirected back
onto itself.  You could do this with mod_rewrite instead of the
'Redirect' directive.  Have it match unless the remote host equals that
of the site2 server, with a [R] parameter to generate a redirect.

But keep in mind that with this solution you're really just redirecting
all traffic to the site2.com server, and nothing will actually be served
from site1.com -- except of course the proxied requests from the
site2.com server.  It really doesn't make any sense to me why you'd want
to do this with two servers instead of just serving everything from a
single server, but I'm sure you have your reasons.

Brian

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