Last active
January 17, 2024 09:59
-
-
Save vladkras/ad103a0f7116e86696b627508b408546 to your computer and use it in GitHub Desktop.
NGINX redirect to app store and google play based on user agent
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
location = /gotoapp { | |
if ($http_user_agent ~* "iphone|ipod|ipad|appletv") { | |
return 301 https://www.apple.com/lae/ios/app-store/; | |
} | |
if ($http_user_agent ~* "android") { | |
return 301 https://play.google.com/store; | |
} | |
if ($http_user_agent ~* "Windows") { | |
return 301 https://www.microsoft.com/store/apps?rtc=1; | |
} | |
if ($http_user_agent ~* "Linux") { | |
return 301 https://www.linux.org/; | |
} | |
if ($http_user_agent ~* "Mac") { | |
return 301 https://www.apple.com/mac/; | |
} | |
return 301 /cant-detect; | |
} |
You should really use a 302 not a 301 for this. 301 is "permanent" and gets cached in the browser, deeply.
302 is evaluated on each request.
https://stackoverflow.com/questions/1393280/http-redirect-301-permanent-vs-302-temporary
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for sharing. Worked only with single quotes for me. That is
'iphone|ipod|ipad|appletv'
instead of"iphone|ipod|ipad|appletv"
for example.