You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by chad phillips <ch...@chadphillips.org> on 2022/04/12 13:01:02 UTC

[users@httpd] Use mod_perl to change URL before reaching mod_rewrite?

Hi,

I want to use mod_perl to change the url before it gets to mod_rewrite, is
this possible?

I currently use mod_rewrite to proxy certain requests to an app server.
    RewriteCond  %{REQUEST_URI} ^/base1/(.*)$  [OR]
    RewriteCond  %{REQUEST_URI} ^/base2/(.*)$
    RewriteRule ^/(.*)$ https://my.appserver.com/$1 [P,L]

This works fine.

I wrote a mod_perl module hoping to change the url BEFORE it gets to
mod_rewrite.  But mod_rewrite still uses the original url.  If I take
mod_rewrite out of the picture, it looks like my perl module does change
the url before Apache tries to hit the file system.

My mod_perl runs as a TransHandler
    PerlTransHandler My::Module

The short of the code is:
 my $uri = $r->uri();
    $uri =~  SOME STUFF HERE TO CHANGE THE URI
    $r->uri($uri); #Internally modify the url

If I am just hitting the file system, Apache uses the modified url from the
perl module.  But if I am using mod_rewrite to proxy, mod_rewrite is using
the original url, before mod_perl makes any changes.

Is it possible to use mod_perl to change the url before mod_rewrite starts
its work?

thank you