Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

Re: Is it possible to get the redirected URL?

by Tanktalus (Canon)
on Dec 15, 2005 at 05:06 UTC ( #516860=note: print w/replies, xml ) Need Help??

in reply to Is it possible to get the redirected URL?

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 "". The CGI script is "". Currently, "" returns a redirect to Pg B. After that, it doesn't currently know anything.

Meanwhile, Pg B is really "", which issues a redirect to, which issues a redirect to

What you want to do is figure out where 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.

  • Comment on Re: Is it possible to get the redirected URL?

Replies are listed 'Best First'.
Re^2: Is it possible to get the redirected URL?
by weilies (Initiate) on Dec 15, 2005 at 08:43 UTC
    First of all i would like to thanks for u guys givin me advises. Sorry if i dint make my problem clear there. :)
    Actually beside Pg A, all is not my control anymore, they are code reside in other domain, so, what i need to do, is making a bot to send out a request (url), like
    Then, their system will based on my 'a_url' to do some processing, then they may have different redirect page based on the validity of my 'a_url',
    let me make some explaination for a_url, actually it is a url with some id pass to their sys. Then their sys will determine what to perform based on my a_url's id, their sys will redirect to 'b_url' if my id got no problem, and other then 'b_url' will be 'not_b_url' shows 'Expired'
    then, i can perform some comparison coz my sys already know the valid url 'b_url'(predefined in my system), coz i m still taking control in my
    if (my_predefined_url eq get_final_landing_pg(a_url)) { return "not expired" } else { return "expired" }
    There wont be any user interruption for the whole process like "click A" for redirect to pg_A or
    "click B" for redirect to pg_B

    Thanks for you guys spending time in reading my question. My broken english really brings up lots of trouble to you guys

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (3)
As of 2021-05-08 01:43 GMT
Find Nodes?
    Voting Booth?
    Perl 7 will be out ...

    Results (95 votes). Check out past polls.