Skip to content

Instantly share code, notes, and snippets.

@TheDome0
Created January 18, 2024 19:00
Show Gist options
  • Select an option

  • Save TheDome0/2e88db31250ce7ee903b80bfc3de0d6b to your computer and use it in GitHub Desktop.

Select an option

Save TheDome0/2e88db31250ce7ee903b80bfc3de0d6b to your computer and use it in GitHub Desktop.
Nginx rules for multilingual sites
set $lang "en";
if ( $http_accept_language ~ ^(..) ) {
set $lang $1;
}
location / {
if ($request_uri ~ ^/(.*).html) {
return 302 /$1$is_args$args;
}
if ($request_uri !~ "^/[a-z]{2}/(.*)") {
return 302 https://$host/$lang$request_uri;
}
try_files $uri $uri.html $uri/ =404;
}
@TheDome0
Copy link
Author

$http_accept_language ~ ^(en|de|zh)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment