perl-modperl mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Michael Peters <mpet...@plusthree.com>
Subject Re: URI redirection
Date Fri, 21 Sep 2007 17:54:49 GMT
Jeff Fulmer wrote:

> I have a functional requirement that is currently delivered with
> mod_rewrite maps but it would be much more maintainable with something
> that offered programmatic logic. I started to look at mod_perl and I
> suspect it might be perfect. I'm using mod_perl version 1.9.x

Well, first piece of advice, ditch that version and upgrade to the latest 2.0.
1.9.x was the 2.x alpha series. It has lots of bugs and depending on which
version you have may be a completely different API.

> I'll have a function that takes a URI as an argument. The function will
> look for that URI in a configure file(s). 

How many URLs are we talking? Depending on how many you have and how much memory
you have it would make sense to read all those urls when apache is started and
put them into a Perl hash. This will make looking them up really fast.

> If it finds a match, it will
> return a URI  to where the client should be redirected. If it doesn't find
> a match, then the client should go to the URI they requested. Let's call
> the function uri_map in the pseudo code below:
> 
> $redirect = uri_map($r->uri);
> if(defined($redirect)){
>   $r->header_out(Location => '/env.jsp');
>   return REDIRECT;
> } else {
>   # and I'm stuck here;
>   # allow the request to pass thru to the server
>   # so that the client goes to the requested URI.

You probably want to run your code as a TransHandler (using the PerlTransHandler
directive. If you did so, you'd just let Apache know what the new url should be
and then tell it your done. See this:

http://perl.apache.org/start/tips/favicon.html

> I'd like to invoke this code for *every* request made to the server. To
> meet that requirement, it seems like <Location /> is a good place to
> reference the handler.

That seems like a good spot. And if you plan on using it for ever request, it's
a good reason to read the url map into memory before you begin.

-- 
Michael Peters
Developer
Plus Three, LP


Mime
View raw message