You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Ime Smits <im...@iae.nl> on 2000/06/04 17:06:43 UTC

mod_perl, mod_rewrite, package namespace

Hi,

I have a script which takes some input variables in the QUERY_STRING, let's
say:

http://localhost/query.pl?archive=1&chapter=2&section=3&subsection=4

This is working fine from the user perspective. But, I found out that most
search engines just discard the querystring, so my site won't get indexed.
Besides of that, urls are quite ugly this way. So what I want to do is do
some mapping between canonical urls and actual scripts on my server, so from
the users perspective, there would be:

http://localhost/query/archive/chapter/section/subsection

To achieve this, I tried both

AliasMatch ^/query/  /path/to/query.pl  (and let query.pl do a
split(/\//,$ENV{REQUEST_URI}))

and

RewriteRule ^/query/(.*) /query.pl?$1    (and let query.pl do a
split(/\//,$ENV{QUERY_STRING}))

These both seemed to work fine, untill I was facing a ps with some 90MB
httpd processes laughing at me. After reviewing /localhost/perl-status it
got clear to me. mod_perl obviously compiles scripts in a namespace derived
from the original REQUEST_URI, so query.pl gets compiled for each and every
combination of arguments.

Does anybody has some pointers on how to get mod_perl to compile query.pl
only once? Maybe by specifying the package namespace manually from within
httpd.conf instead of letting mod_perl do the job based on REQUEST_URI?

Ime




Re: mod_perl, mod_rewrite, package namespace

Posted by Ime Smits <im...@iae.nl>.
Hi,

I just wanted to let you know that (once again) re-RTFM the manual *twice*
solved my muliple compilation problem. The solution is adding [PT] to the
RewriteRule.

RewriteRule ^/query/(.*) /query.pl?$1 [PT]

--
http://www.apache.org/docs/mod/mod_rewrite.html:

'passthrough|PT' (pass through to next handler)
This flag forces the rewriting engine to set the uri field of the internal
request_rec structure to the value of the filename field. This flag is just
a hack to be able to post-process the output of RewriteRule directives by
Alias, ScriptAlias, Redirect, etc. directives from other URI-to-filename
translators. A trivial example to show the semantics: If you want to rewrite
/abc to /def via the rewriting engine of mod_rewrite and then /def to /ghi
with mod_alias:
    RewriteRule ^/abc(.*)  /def$1 [PT]
    Alias       /def       /ghi

If you omit the PT flag then mod_rewrite will do its job fine, i.e., it
rewrites uri=/abc/... to filename=/def/... as a full API-compliant
URI-to-filename translator should do. Then mod_alias comes and tries to do a
URI-to-filename transition which will not work.
Note: You have to use this flag if you want to intermix directives of
different modules which contain URL-to-filename translators. The typical
example is the use of mod_alias and mod_rewrite..