Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jamesnguyen101/14b8b48cf338e3f2233e77669c959d38 to your computer and use it in GitHub Desktop.
Save jamesnguyen101/14b8b48cf338e3f2233e77669c959d38 to your computer and use it in GitHub Desktop.
Nginx Redirect if useragent is android or iphone
# 1
location / {
set $mobile 0;
if ($http_user_agent ~* "iphone|android") {
set $mobile 1;
}
if ($mobile = 1) {
# return or rewrite to somewhere
}
}
# 2
location / {
try_files $uri @mobile;
}
location @mobile {
set $mobile 0;
if ($http_user_agent ~* "iphone|android") {
set $mobile 1;
}
if ($mobile = 1) {
# return or rewrite to somewhere
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment