|
Ngxin implement user-agent to access the page without very simple, but we usually tip the cache layer, the layer of how to achieve in the cache, the same principles.
Today, with Varnish realize, notice that we realize that 302 redirect instead rewrite url
Goals: iphone to access www.abc.com will automatically jump to m.abc.com
Paste the code
sub vcl_recv {
if (req.http.user-agent ~ "iphone") {
if (req.http.host ~ "www.abc.com") {
error 750 "m.abc.com";
}
}
}
sub vcl_error {
if (obj.status == 750) {
if (obj.response ~ "m.abc.com") {
set obj.http.Location = "http://m.abc.com/";
}
set obj.status = 302;
return (deliver);
}
} |
|
|
|