CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: mod_perl:
Mobile detection redirect

 



mhassan
Novice

Feb 15, 2010, 1:35 PM

Post #1 of 1 (3362 views)
Mobile detection redirect Can't Post

Hi,
I am new to perl. I am working on mobile detection and url redirect. The mobile detection works. But the redirect doesn't.

When the user requests somesite.com. I want it to redirect to mobile.somesite.com. In my virtual host file for somesite.com I have a code:



Code
    <LocationMatch "/*.html$"> 
Order deny,allow
Allow from all
SetHandler modperl
PerlHeaderParserHandler Cookie
PerlFixupHandler APS::Session
PerlResponseHandler AppKeyCookie
Header set P3P 'CP="CAO DSP COR LAW CURa ADMa DEVa PSAa PSDa OUR DELa BUS IND PHY ONL UNI PUR COM NAV INT STA"'
PerlLogHandler LogError
</LocationMatch>


In AppKeyCookie:


Code
package AppKeyCookie; 
use strict;

use Apache2::Request;
use Apache2::RequestRec;
use Apache2::RequestUtil;
use Apache2::URI;
use Apache2::Cookie;
use Data::Dumper;
use HTTP::Date;
use Apache2::Const -compile => qw(:common);
use IO::File;
use WFC::Wurfl;

my $r = shift;
my $file = $r->filename;
my $host = $r->hostname;
my $uri = $r->uri;

if ($host eq 'mobile.somesite.com' || $r->prev){
print STDERR "host is $host\n";
$r->content_type('text/html');
$r->err_headers_out->add('Location' => 'iphone/index.html');
return Apache2::Const::REDIRECT;
} elsif ($host eq 'somesite.com'){
my $ua = $r->headers_in()->{'User-Agent'};
my $wurfl = WFC::Wurfl->new;
my $mobile = $wurfl->is_mobile($ua);
if ($mobile){ #this works!
my $new_host = $r->hostname('mobile.dev.where2getit.com');
my $new_uri = 'http://mobile.dev.where2getit.com/chickfila/index.html';
$r->internal_redirect($new_uri);
return Apache2::Const::OK;
}
}
1;


In firefox I set the 'user agent' to Blackberry 8320. When I request the site I get "Firefox has detected that the server is redirecting the request for this address in a way that will never complete."

In error log, It does prints that the site was mobile. Since I am printing it in log if its mobile.

I want it to redirect to mobile.somesite.com/iphone.html. Any ideas how internal_redirects works. Or any other way to work on this?

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives