Skip to content

Instantly share code, notes, and snippets.

@ankibalyan
Created October 9, 2017 09:15
Show Gist options
  • Save ankibalyan/388d7de1f5475d8ed85b367e490c7551 to your computer and use it in GitHub Desktop.
Save ankibalyan/388d7de1f5475d8ed85b367e490c7551 to your computer and use it in GitHub Desktop.
Redirects from nginx based on user agent
# APP redirects
if ($http_user_agent ~* "iphone|ipod|ipad|appletv") {
rewrite ^/adl/(.*)$ https://itunes.apple.com/us/app/apple-store/id375380948?mt=8&params=$1 redirect;
}
if ($http_user_agent ~* "android") {
rewrite ^/adl/(.*)$ https://play.google.com/store/apps/details?id=com.app.witpay&params=$1 redirect;
}
if ($http_user_agent ~* "Windows") {
rewrite ^/adl/(.*)$ https://example.com/$1 redirect;
}
if ($http_user_agent ~* "Linux") {
rewrite ^/adl/(.*)$ https://example.com/$1 redirect;
}
if ($http_user_agent ~* "Mac") {
rewrite ^/adl/(.*)$ https://example.com/$1 redirect;
}
# rewrite ^/adl/(.*)$ https://example.com/$1 redirect;
# PWA redirect
if ($is_mobile) {
return 301 https://m.example.com/$request_uri;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment