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

I am trying to do a redirect under mod_perl...the script is run under Apache::Registry. I am using $r->internal_redirect(..) to do the redirect so that I don't need to bounce back to the client to have them make another request.

The redirection is working fine but for some reason the query string from the initial request is being carried over to the redirection.

Is there any way to do an internal_redirect so that the request processing starts over from the beginning without having to go back to the client first?

Thanks,
Kenny

Replies are listed 'Best First'.
Re: Apache::Registry and redirection
by perrin (Chancellor) on Sep 29, 2006 at 19:40 UTC
    You're using CGI.pm, right? It doesn't know about your internal redirect. You need to call CGI::initialize_globals() after the internal redirect.
      That doesn't seem to work...still get the exact same results. Here is my subroutine:

      sub redirect { my $new_url = shift; my $include_old_url = shift; my $redirect = q{http://} . const('host') . $new_url; $redirect .= q{?} if $redirect !~ /\?/; $redirect .= q{&redirect=} . escape(url()) if $include_old_url; my $request = Apache->request(); $request->internal_redirect($redirect); CGI::initialize_globals(); return; }

      I am basically trying to do an entirely new request to the apache server without alerting the client.

        It doesn't work because it doesn't come back here until your redirect is over, so it doesn't run that code. You have to run the initialize_globals call in your subrequest that you redirected to. You can try calling it just before the internal_redirect, but I'm not sure that will work.