Mobile redirects

Audun Ytterdal audun at ytterdal.net
Tue Apr 13 10:09:50 CEST 2010


Ops. Accidently hit send button...

On Tue, Apr 13, 2010 at 10:06 AM, Audun Ytterdal <audun at ytterdal.net> wrote:
> On Tue, Apr 13, 2010 at 9:49 AM, Morten Bekkelund <morten at startsiden.no> wrote:
>> Hi Rob.
>>
>> I used the mobile redirect part of Alexc's example and created a simplified version
>> on our test-servers. It worked well.
>>
>> http://dingleberry.me/2010/03/mobile-redirects-using-varnish/
>
I've used this method:

sub vcl_recv {
        <.....>
        call identify_device;
 }

sub identify_device {
        unset req.http.hash-input;
        set req.http.X-VG-Device = "pc";
        if (!req.url ~
"^/[^?]+\.(jpeg|jpg|png|gif|ico|js|css|txt|gz|zip|lzma|bz2|tgz|tbz|html|htm)(\?.*|)$")
{
                if (req.http.Cookie ~ "vg_nomobile") {
                        set req.http.X-VG-Device = "pc-forced";
                }
                elsif (req.http.User-Agent ~ "iP(hone|od)") {
                        set req.http.X-VG-Device = "mobile-iphone";
                }

                elsif (req.http.User-Agent ~ "^HTC" ||
                req.http.User-Agent ~ "IEMobile" ||
                req.http.User-Agent ~ "Android") {
                        set req.http.X-VG-Device = "mobile-smartphone";
                }
                elsif (req.http.User-Agent ~ "SymbianOS" ||
                req.http.User-Agent ~ "^BlackBerry" ||
                req.http.User-Agent ~ "^SonyEricsson" ||
                req.http.User-Agent ~ "^Nokia" ||
                req.http.User-Agent ~ "^SAMSUNG" ||
                req.http.User-Agent ~ "^LG") {
                        set req.http.X-VG-Device = "mobile-dumbphone";
                }
        }
        if (req.http.X-VG-Device != "pc" && req.http.X-VG-Device !=
"pc-forced") {
                set req.http.hash-input = req.http.X-VG-Device;
        }
}

sub vcl_hash {
        set req.hash += req.http.hash-input;
}

And then the backend apache or the php-scripts can decide what to
present to the client...

So then you have a few choises

1) Apache sends redirect if X-VG-Devvice = ^mobile
2) Apache rewrites/proxyes
3) Php-code redirects or just presents a different template

-- 
Audun Ytterdal
http://audun.ytterdal.net




More information about the varnish-misc mailing list