Mobile redirect question

Caunter, Stefan scaunter at topscms.com
Tue Mar 29 15:53:41 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.*|.*ht
c.*|.*Huawei.*|.*iPhone.*|.*iPod.*|.*MobilePhone.*|.*Motorola.*|.*nokia.
*|.*Novarra.*|.*O2.*|.*Palm.*|.*Samsung.*|.*Sanyo.*|.*Smartphone.*|.*Son
yEricsson.*|.*Symbian.*|.*Toshiba.*|.*Treo.*|.*vodafone.*|.*Xda.*|^Alcat
el.*|^Amoi.*|^ASUS.*|^Audiovox.*|^AU-MIC.*|^BenQ.*|^Bird.*|^CDM.*|^DoCoM
o.*|^dopod.*|^Fly.*|^Haier.*|^HP.*iPAQ.*|^i-mobile.*|^KDDI.*|^KONKA.*|^K
WC.*|^Lenovo.*|^LG.*|^NEWGEN.*|^Panasonic.*|^PANTECH.*|^PG.*|^Philips.*|
^portalmmm.*|^PPC.*|^PT.*|^Qtek.*|^Sagem.*|^SCH.*|^SEC.*|^Sendo.*|^SGH.*
|^Sharp.*|^SIE.*|^SoftBank.*|^SPH.*|^UTS.*|^Vertu.*|.*Opera.Mobi.*|.*Win
dows.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


set req.http.newhost = regsub(req.url, "^/(.*)",
"http://m.example.ca/\1");

Stef




More information about the varnish-misc mailing list