FAQ 9.11 How do I redirect to another page?

Discussion in 'Perl Misc' started by PerlFAQ Server, Apr 19, 2011.

  1. This is an excerpt from the latest version perlfaq9.pod, which
    comes with the standard Perl distribution. These postings aim to
    reduce the number of repeated questions as well as allow the community
    to review and update the answers. The latest version of the complete
    perlfaq is at http://faq.perl.org .

    --------------------------------------------------------------------

    9.11: How do I redirect to another page?

    Specify the complete URL of the destination (even if it is on the same
    server). This is one of the two different kinds of CGI "Location:"
    responses which are defined in the CGI specification for a Parsed
    Headers script. The other kind (an absolute URLpath) is resolved
    internally to the server without any HTTP redirection. The CGI
    specifications do not allow relative URLs in either case.

    Use of "CGI.pm" is strongly recommended. This example shows redirection
    with a complete URL. This redirection is handled by the web browser.

    use CGI qw/:standard/;

    my $url = 'http://www.cpan.org/';
    print redirect($url);

    This example shows a redirection with an absolute URLpath. This
    redirection is handled by the local web server.

    my $url = '/CPAN/index.html';
    print redirect($url);

    But if coded directly, it could be as follows (the final "\n" is shown
    separately, for clarity), using either a complete URL or an absolute
    URLpath.

    print "Location: $url\n"; # CGI response header
    print "\n"; # end of headers



    --------------------------------------------------------------------

    The perlfaq-workers, a group of volunteers, maintain the perlfaq. They
    are not necessarily experts in every domain where Perl might show up,
    so please include as much information as possible and relevant in any
    corrections. The perlfaq-workers also don't have access to every
    operating system or platform, so please include relevant details for
    corrections to examples that do not work on particular platforms.
    Working code is greatly appreciated.

    If you'd like to help maintain the perlfaq, see the details in
    perlfaq.pod.
    PerlFAQ Server, Apr 19, 2011
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. NWx
    Replies:
    3
    Views:
    466
  2. =?Utf-8?B?VHJveQ==?=

    Response.redirect does not redirect from .aspx page

    =?Utf-8?B?VHJveQ==?=, Oct 18, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    5,233
    Srowe1975
    Oct 15, 2008
  3. varmansk
    Replies:
    0
    Views:
    487
    varmansk
    Nov 30, 2008
  4. Sal
    Replies:
    1
    Views:
    405
  5. Robert Cohen
    Replies:
    3
    Views:
    268
    Andrew Durstewitz
    Jul 15, 2003
Loading...

Share This Page