It's a bit unclear to me what exactly you're trying to do. I'm going to fathom a guess, including some hand-waving, and you'll have to tell me if I'm on the right track.

You have a CGI script running on a machine named "www.domain.com". The CGI script is "a.pl". Currently, "a.pl" returns a redirect to Pg B. After that, it doesn't currently know anything.

Meanwhile, Pg B is really "b.pl", which issues a redirect to c.pl, which issues a redirect to d.pl.

What you want to do is figure out where b.pl is really going to go, and just issue the redirect directly to the last place.

If this is a correct guess on what you're looking for, my humble suggestion is "don't." As in, don't short-circuit this. It's incredibly error-prone in the general case, and mildly annoying in specific cases where there is a general-purpose tool available to do it for you (i.e., the browser).

There are a number of ways to be redirected. The most obvious is a "page moved" response. There's also meta-redirect tags, or even Javascript. Do you want/need to handle all of these?

Further, Pg B (or Pg C) may or may not be a script (you can't always tell - just because it ends with ".html" doesn't mean it's not dynamic). And they may do different redirections based on cookies the user has ("not authorised - go away"). Or they may do other processing ("User clicked on 'pg b' in a form that needs some other processing - send them to pg c so that it can be processed, then pg c figures out that there's stuff missing, so sends the user to an error page, page d"). There is a lot of context that you need to be aware of. Allowing the browser to do it means that you can really simplify the code and ensure everything is correct easier.

That said, if all of this really lived inside the same set of perl modules, you could simply call the other pages directly and let them figure out what to do. This would be relatively simple in CGI::Application, as it would, I'm sure, under a number of other systems. Just call the next function directly - you save a lot of processing (both the client and the server) and associated network overhead this way. But the key here is to call the worker functions that are identical whether you're redirecting or just calling the next function in the series (except for a decision point on whether to redirect or call the next function). Again, this can simplify your workload as the developer while still saving that extra overhead for the server and the user.


In reply to Re: Is it possible to get the redirected URL? by Tanktalus
in thread Is it possible to get the redirected URL? by weilies

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.