in reply to Perl/CGI redirect.

As far as I know it's usually not a problem to have the header printed and then redirect basically but it could be depending on server/configuration. I would try to replace the /login.html with a full url like http://myserver/login.html, which solves the problem in most cases. If that also don't works I would try to just do a print q(<META HTTP-EQUIV="refresh" CONTENT="n; URL=http://foo.bar/">); -> helped me in one case but I still don't know why tbh...

greets,
giant


-----BEGIN PERL GEEK CODE BLOCK-----
Version: 0.01
P++>+++$c-> P6 >+R+>+M+>++O
>+MA+>+++E+>++PU+>+++BD C+>++D!S X!WP
>+++MO?PP++n CO?PO-o+G
A--OL!Ee---Ev++Eon!Eot!Eob!Eoa!uL++uB
uS!uH+uo+w---m!osA-osBE-
------END PERL GEEK CODE BLOCK------

Replies are listed 'Best First'.
•Re: Re: Perl/CGI redirect.
by merlyn (Sage) on May 20, 2002 at 12:57 UTC
    As far as I know...
    Hopefully, the people reading your node will know from the way you start your answer that the remaining text is not to be trusted. {grin}

    I suggest you read the rest of the messages in this thread, and others, before answering on this subject again. Your statement contained many vaguenesses and a few misleading (and incorrect) claims.

    In brief:

    • No, you can't have both a normal header and a redirect.
    • A body HTML redirect is not the same as a header redirect, and is generally frowned upon except in the rare case that you don't have control of the headers. Of course, in CGI, you have complete control of the headers, so this is never needed in a CGI world. And a body HTML redirect messes up your back button.
    • A header redirect is an instruction to the webserver. If this contains a full URL, then it's an external redirect passed to the browser. If it's just an absolute path, it's an internal redirect. These have different distinct and useful purposes, and it's good to know how to use both.
    So you were kinda 0 for 3 there.

    Your willingness to help is appreciated and noted, however.

    -- Randal L. Schwartz, Perl hacker

      Uhm okay I feel sorry then for posting wrong stuff on this one. But the one with the full-URL is even in perldoc CGI:

      One hint I can offer is that relative links may not work correctly when you generate a redirection to another docu�
      ment on your site. This is due to a well-intentioned optimization that some servers use. The solution to this is to use the full URL (including the http: part) of the document you are redirecting to.

      But anyway I'll go back to the books and think more carefully before I post something next time, because it's really bad to post wrong stuff :(

      /me asks the gods for mercy and goes back to meditation...
        One hint I can offer is that relative links may not work correctly when you generate a redirection to another docu? ment on your site. This is due to a well-intentioned optimization that some servers use. The solution to this is to use the full URL (including the http: part) of the document you are redirecting to.
        I know that quote. That's not talking about /fred/barney/dino.txt. That's talking about just barney/dino.txt, which does in fact have problems in some situations. The "solution" is overkill (always use an external redirect), but successful. An internal redirect (one that is an absolute path without a scheme or hostname) is also valid for some operations, and it's important to know when.

        -- Randal L. Schwartz, Perl hacker