需求:通过User Agent判断手机用户,重定向到手机页面。
首先看github上面的例子,或者直接看官网。
其实很简单,直接来吧
#判断是否有手机ua关键字的,举了些例子。
function isMobile(userAgent)
ua_array = {
'android','iphone','ipad','mqqbrowser','windows phone','huawei','htc','meizu','oppo','vivo','xiaomi'}
n = table.getn(ua_array)
for i= 1, n do
if(string.match(userAgent,ua_array[i])) then
return true
end
end
return false
end
#在返回的header里面加入Location,即302之后的地址。
function send_response()
if(remap_url) then
ts.client_response.header['Location'] = remap_url
end
return 0