Mobile redirect question

Bjørn Ruberg bjorn at ruberg.no
Tue Mar 29 15:04:33 CEST 2011


On 29. mars 2011 14:56, Maikel - Songteksten.nl wrote:
> Hi,
>
> I'm using currently the following code to do a mobile site redirect. I
> found it somewhere on the internet.
>
> if ( req.http.user-agent ~
> "(.*Android.*|.*Blackberry.*|.*BlackBerry.*|.*Blazer.*|.*Ericsson.*|.*htc.*|.*Huawei.*|.*iPhone.*|.*iPod.*|.*MobilePhone.*|.*Motorola.*|.*nokia.*|.*Novarra.*|.*O2.*|.*Palm.*|.*Samsung.*|.*Sanyo.*|.*Smartphone.*|.*SonyEricsson.*|.*Symbian.*|.*Toshiba.*|.*Treo.*|.*vodafone.*|.*Xda.*|^Alcatel.*|^Amoi.*|^ASUS.*|^Audiovox.*|^AU-MIC.*|^BenQ.*|^Bird.*|^CDM.*|^DoCoMo.*|^dopod.*|^Fly.*|^Haier.*|^HP.*iPAQ.*|^i-mobile.*|^KDDI.*|^KONKA.*|^KWC.*|^Lenovo.*|^LG.*|^NEWGEN.*|^Panasonic.*|^PANTECH.*|^PG.*|^Philips.*|^portalmmm.*|^PPC.*|^PT.*|^Qtek.*|^Sagem.*|^SCH.*|^SEC.*|^Sendo.*|^SGH.*|^Sharp.*|^SIE.*|^SoftBank.*|^SPH.*|^UTS.*|^Vertu.*|.*Opera.Mobi.*|.*Windows.CE.*|^ZTE.*)"
>
>          &&  req.http.host ~ "(www.example.nl|www.example.be)"
>
>          ) {
>
>          set req.http.newhost = regsub(req.http.host, "(www)?\.(.*)",
> "http://m.\2");
>          error 750 req.http.newhost;
>
> The redirect from www.example.nl to m.example.nl works perfectly, only
> www.example.nl/page.php?id=1 also redirect to m.example.nl (so withou
> the page.php?id=1 part).
>
> Is it possible to change the redirect so it also includes the rest of
> the url?

You don't show how error 750 is handled in your VCL, so it's a bit hard 
to tell how to improve your current config. However, the following URL 
should get you going:

http://www.varnish-cache.org/trac/wiki/VCLExampleHostnameRemapping

-- 
Bjørn





More information about the varnish-misc mailing list