Created
February 17, 2019 10:35
-
-
Save woecifaun/010c5b282b7a4c54f2cccde94c53f1a4 to your computer and use it in GitHub Desktop.
Nginx lang redirection depending on preferred user (accept) language
This file contains 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
server { | |
listen 80; | |
charset UTF-8; | |
# Language | |
set $user_langs ",$http_accept_language"; | |
set $first_available_language "en"; | |
if ($user_langs ~* ',{1}(en|fr)') { | |
set $first_available_language $1; | |
} | |
# Redirect root page depending on user and site languages | |
rewrite ^/$ "$scheme://$host/$first_available_language" redirect; | |
server_name mydomain.com www.mydomain.com ; | |
… | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment