mod_perl vs. mod_rewrite precedence?

mod_perl vs. mod_rewrite precedence?

am 08.06.2010 20:24:28 von E R

I'm trying to figure out how mod_perl and mod_rewrite work together.
This is with Apache 1.3.41, mod_perl 1.30, perl 5.8,9.

It seems that if there is a mod_perl handler installed at a location,
a mod_rewrite rule rewriting that location to another doesn't have any
effect.

Below is a sample httpd.conf file. It installs mod perl handlers at
/perl1 and /perl2. The mod_rewrite rules rewrite /perl2 -> /foo.txt (a
file which exists), /bar -> /foo.txt and /baz -> /perl1.

Here is what I am seeing:

GET /perl2 -> returns the output of the mod-perl handler
GET /bar -> returns the contents of the file foo.txt (as expected)
GET /baz -> returns a 404 error; inspecting the rewrite log file shows
that it is trying to serve the file DOCUMENT_ROOT/perl1

Can anyone explain what is going on?

Thanks,
ER

RewriteEngine On
RewriteLog /tmp/rewrite

RewriteCond %{REQUEST_URI} ^/perl2 [NC]
RewriteRule .* /foo.txt [L]

RewriteCond %{REQUEST_URI} ^/bar [NC]
RewriteRule .* /foo.txt [L]

RewriteCond %{REQUEST_URI} ^/baz [NC]
RewriteRule .* /perl1 [L]

RewriteLogLevel 9


package MyHandler;
use Apache::Constants qw(OK);
sub handler {
my $r = shift;
$r->content_type("text/plain");
$r->print("Now is @{[scalar(localtime(time))]}\n");
return OK;
}
package ApacheReadConfig;
my $app = {
SetHandler => 'perl-script',
PerlHandler => 'MyHandler',
};
$Location{'/perl1'} = $app;
$Location{'/perl2'} = $app;

Re: mod_perl vs. mod_rewrite precedence?

am 15.06.2010 11:09:11 von Vincent Veyron

E R wrote:
> It seems that if there is a mod_perl handler installed at a location,
> a mod_rewrite rule rewriting that location to another doesn't have any
> effect.
>
I noticed that with mod_dir in Apache2 : it won't redirect for 'trailing
slash' if a handler is configured for that location.

I add the redirection code to the handler myself :

if ( $r->uri =~ /\/$/ ) {

my $location = $r->uri . 'index.html' ;

$r->headers_out->set(Location => $location);

return Apache2::Const::REDIRECT;

}



--

Vincent Veyron
Logiciel de suivi et de gestion des dossiers de contentieux et d'assurance pour les services juridiques
http://marica.fr/