Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

How do I redirect to another page?

by faq_monk (Initiate)
on Oct 08, 1999 at 00:32 UTC ( [id://765]=perlfaq nodetype: print w/replies, xml ) Need Help??

Current Perl documentation can be found at perldoc.perl.org.

Here is our local, out-dated (pre-5.6) version:

Instead of sending back a Content-Type as the headers of your reply, send back a Location: header. Officially this should be a URI: header, so the CGI.pm module (available from CPAN) sends back both:

    Location: http://www.domain.com/newpage
    URI: http://www.domain.com/newpage

Note that relative URLs in these headers can cause strange effects because of ``optimizations'' that servers do.

    $url = "http://www.perl.com/CPAN/";;
    print "Location: $url\n\n";
    exit;

To be correct to the spec, each of those "\n" should really each be "\015\012", but unless you're stuck on MacOS, you probably won't notice.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (5)
As of 2024-04-19 02:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found