Boldra has asked for the wisdom of the Perl Monks concerning the following question:

I need to add a perl module to our site to redirect all users with a certain cookie set, regardless of the page they are requesting (ie. static or CGI). The redirection will need to send users to a completely different domain, so it's not a job for PerlTransHandler.

So my question is this; which mod_perl handler should I use for the redirection? My first guess was doing it bright and early at PerlPostReadRequestHandler, but maybe there is a good reason I should use PerlHandler or something else later?

Has anyone got any experience with this?

  • Comment on Redirection using a mod_perl handler (PerlPostReadRequestHandler ?)

Replies are listed 'Best First'.
Re: Redirection using a mod_perl handler (PerlPostReadRequestHandler ?)
by merlyn (Sage) on Nov 14, 2000 at 17:38 UTC
    If it needs to be done "very very early" I tend to use PerlInitHandler which translates to either PostReadRequestHandler if in the configuration files, or PerlHeaderParserHandler if in a post-trans location, like an .htaccess file. Both of those are as soon as possible in that phase.

    However, if you already have a PerlTransHandler, you can just drop this code into it:

    use Apache::Constants qw(REDIRECT); # if you don't already have it sub handler { my $r = shift; # normal {grin} ... if (detect your cookie here) { $r->header_out(Location => "http://web.stonehenge.com/perltraining +/"); return REDIRECT; } ... }
    I don't play much with cookies, so I don't have any examples of detecting the cookie, but I presume you do. {grin} Oh yeah, and change that sample URL unless you want them to Learn some more Perl from some Experts. {grin} </code>

    -- Randal L. Schwartz, Perl hacker