Skip to content

Instantly share code, notes, and snippets.

@woecifaun
Created February 17, 2019 10:35
Show Gist options
  • Save woecifaun/010c5b282b7a4c54f2cccde94c53f1a4 to your computer and use it in GitHub Desktop.
Save woecifaun/010c5b282b7a4c54f2cccde94c53f1a4 to your computer and use it in GitHub Desktop.
Nginx lang redirection depending on preferred user (accept) language
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