The code below worked for me for Mod Perl 2.
use Apache2::Const -compile => qw(OK DECLINED REDIRECT);
my $r = shift;
my $url = 'http://www.google.com';
$r->headers_out->set(Location => $url);
$r->status(Apache2::Const::REDIRECT);
But something strange happens often. when I call the link in a browser it displays a blank page. But if I refresh a couple of times, it goes to google.com. As the below output of 'Live HTTP headers' indicates I get 200 OK page instead of a 302 page.
FYI, I have setup local DNS resolution for modperllab.com and I use ModPerl::Registry as the Response Handler.
http://www.modperllab.com/migration/redirect_tests.pl
GET /migration/redirect_tests.pl HTTP/1.1
Host: www.modperllab.com
User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.0.18) Gec
+ko/2010021718 CentOS/3.0.18-1.el5.centos Firefox/3.0.18 GTB7.1
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.
+8
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive
HTTP/1.1 200 OK
Date: Mon, 15 Nov 2010 09:35:17 GMT
Server: Apache/2.2.8 (CentOS)
Location: http://www.gmail.com
Content-Length: 0
Connection: close
Content-Type: text/plain; charset=UTF-8
Any ideas ?
Thanks.
Mohammed Shakir |