Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
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 avoiding work at the Monastery: (3)
As of 2025-06-15 00:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.