You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Octavian Rasnita <or...@fcc.ro> on 2005/09/30 22:36:31 UTC
redirecting
Hi,
I am trying to redirect a request to another location and the following code
works, but the new location is not printed in the address bar.
$r->status_line('302 Moved');
$r->headers_out->add('Location' => 'http://localhost/');
return Apache2::Const::OK;
return Apache2::Const::REDIRECT; #gives the same result.
Thanks.
Teddy
Teddy
Re: redirecting
Posted by ___cliff rayman___ <cl...@rayman.com>.
Michael Hall wrote:
>Try simply:
>
>$r->headers_out->set(Location => 'to-URI');
>
>
make sure 'to-URI' is absolute and not relative as per the RFC's. I
have had some problems with relative URI's since Apache tends to want to
optimize the call. Instead of sending the 302 headers to the browser,
apache internally redirects to the relative URI. Since the web
designers were calling our routines to do the redirects, we had to write
a regex to take relative URI's and convert them to absolute before
setting the headers.
Cliff
>return Apache2::Const::REDIRECT;
>
>The status of 302 is set automatically and my browsers reflect the new address.
>apache sends:
>
>HTTP/1.1 302 Found
>Date: Sun, 02 Oct 2005 06:00:12 GMT
>Server: Apache
>Location: to-URI
>Content-Length: 290
>Content-Type: text/html; charset=iso-8859-1
>
><!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
><html><head>
><title>302 Found</title>
></head><body>
><h1>Found</h1>
><p>The document has moved <a href="to-URI">here</a>.</p>
><hr>
><address>Apache Server at localhost Port 80</address>
></body></html>
>
>
>Michael
>
>
--
_____cliff_rayman_____________________________________
Business Consulting and Turnaround Management
[web] http://www.rayman.com/
[web] http://all-clear-turnaround-management.com/
[eml] cliff __at__ rayman.com
[phn] 888-736-3802 x701
[fax] 818-743-7404
______________________________________________________
Re: redirecting
Posted by Michael Hall <mi...@gmail.com>.
Try simply:
$r->headers_out->set(Location => 'to-URI');
return Apache2::Const::REDIRECT;
The status of 302 is set automatically and my browsers reflect the new address.
apache sends:
HTTP/1.1 302 Found
Date: Sun, 02 Oct 2005 06:00:12 GMT
Server: Apache
Location: to-URI
Content-Length: 290
Content-Type: text/html; charset=iso-8859-1
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>302 Found</title>
</head><body>
<h1>Found</h1>
<p>The document has moved <a href="to-URI">here</a>.</p>
<hr>
<address>Apache Server at localhost Port 80</address>
</body></html>
Michael