Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Re: cgi redirect (again)

by Kanji (Parson)
on Dec 03, 2002 at 15:50 UTC ( [id://217257]=note: print w/replies, xml ) Need Help??


in reply to •Re: cgi redirect (again)
in thread cgi redirect (again)

I haven't been able to find any reference documenting this behaviour, but I've never been able to force an internal redirect on Apache unless I omitted the Status: header (which redirect() adds by default) using...

print $q->redirect( -status => "", -uri => "/cgi-bin/Auto.cgi" );
...or even...
print "Location: /cgi-bin/Auto.cgi\n\n";

Maybe you'll have better luck with one of these?

    --k.


Replies are listed 'Best First'.
•Re: Re: Re: cgi redirect (again)
by merlyn (Sage) on Dec 03, 2002 at 16:08 UTC
    Aha! I found the culprit! You were spot on, although slightly confused. Apache does notice the status header of an internal redirect. Here's the code:
    location = ap_table_get(r->headers_out, "Location"); if (location && location[0] == '/' && r->status == 200) {
    So if there's a status, it has to be "200". Any other status, and the code falls through to sending the header out to the client instead (an external redirect).

    And there appears to be no-way to force a 200 status using CGI.pm's "redirect". {sigh}

    -- Randal L. Schwartz, Perl hacker
    Be sure to read my standard disclaimer if this is a reply.


    update: Ahh. I was wrong about CGI.pm. You can use
    print redirect(-uri => "/foo", -status => 200);
      Super, always pleased to learn new stuff.

      So what is happening is that the CGI.pm is sending headers to Apache to send back to the client. However Apache notices that the status is 200 and that there is a Location header and decides to issue a new request through itself for this location. So until the new location's data is grabbed and is ready to go back nothing is sent to the client making this an internal, as opposed to external, redirect.

      So without forcing a status of 200 CGI.pm redirect would send back a status of 302 (Moved Temporarily) which Apache would send on to the brower to deal with.

      I believe I am clear an this now, thanks for the clarification.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://217257]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (4)
As of 2024-04-24 20:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found