httpd-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jerome Schevingt" <l...@nightrain.com>
Subject Re: [users@httpd] Help me please .. Mod_rewrite
Date Mon, 02 Feb 2004 15:33:53 GMT
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" <brian@dessent.net>
To: <users@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


Mime
View raw message