Skip to content

Instantly share code, notes, and snippets.

@peaceman
Created July 10, 2020 13:18
Show Gist options
  • Save peaceman/2b0a11d8d7c5fde766d6249976980cef to your computer and use it in GitHub Desktop.
Save peaceman/2b0a11d8d7c5fde766d6249976980cef to your computer and use it in GitHub Desktop.
nginx locale redirect
# locale redirect
if ($http_accept_language ~* "^en") {
set $locale_specific_subdomain "en";
}
if ($http_accept_language ~* "^fr") {
set $locale_specific_subdomain "fr";
}
if ($http_accept_language ~* "^da") {
set $locale_specific_subdomain "dk";
}
if ($http_accept_language ~* "^it") {
set $locale_specific_subdomain "it";
}
if ($http_accept_language ~* "^es") {
set $locale_specific_subdomain "es";
}
if ($http_accept_language ~* "^nl") {
set $locale_specific_subdomain "nl";
}
location = / {
add_header Vary "Accept-Language";
error_page 461 = @shopware; // as default
if ($http_accept_language ~* "^de") {
return 461;
}
return 303 https://$locale_specific_subdomain.example.com;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment