Search code examples
http-redirectmod-perl

mod_perl redirect


So I'm working in a mod_perl environment, and I want to know what the best way is to redirect to a new url. I know in CGI Perl you use print "Location:...", however I've come to find that usually there are better ways to do things in mod_perl, but I can't seem to find anything. Thanks in advance!


Solution

  • use Apache2::Const -compile => qw(REDIRECT);
    sub handler {
      my $r = shift;
      $r->headers_out->set( Location => $url);
      $r->status(Apache2::Const::REDIRECT); #302
    }
    

    This is the answer for how to properly redirect in mod_perl2