http-user-agent #
Sorts clients into groups by their User-Agent string, such as browser name and version, and stores the group in a variable. Use it to serve different content or rules to old browsers, crawlers or mobile clients. It comes from Tengine.
Source: upstream source
Directives
user_agent #
syntax: user_agent 1 arg; · context: http
E.g 1. "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; Trident/6.0)", this string is MSIE's user_agent string, we will return when we find the keyword "MSIE".
Example
map $http_user_agent $is_mobile {
default 0;
"~*(?:Android|iPhone|iPad|Mobile)" 1;
}
location / {
if ($is_mobile) {
rewrite ^ /m$uri last;
}
}