David Stewart wrote:
How do you replicate the redirect functionality of mod_rewrite in a
mod_perl 2 PerlTransHandler?
I'm writing a PerlTransHandler to overcome some limitation of
mod_rewrite and want to redirect requests to canonical URLs in some
cases (e.g. replicate the functionality of the [R,L] flags in
mod_rewrite). What's the best way to do this from the handler?
Here are some obviously simplified, untested examples, i think R is a
302, but i've included the 301 as well.
for a 302:
use Apache2::RequestRec;
use Apache2::Const -compile => qw(REDIRECT);
sub handler {
my $r = shift
$r->err_headers_out->add(Location => q[your url here]);
return Apache2::Const::REDIRECT;
}
1;
for a 301:
use Apache2::RequestRec;
use Apache2::Const -compile => qw(HTTP_MOVED_PERMANENTLY);
sub handler {
my $r = shift;
$r->err_headers_out->add(Location => q[your url here]);
return Apache2::Const::HTTP_MOVED_PERMANENTLY;
}
1;
Adam