Created
January 18, 2024 19:00
-
-
Save TheDome0/2e88db31250ce7ee903b80bfc3de0d6b to your computer and use it in GitHub Desktop.
Nginx rules for multilingual sites
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
| 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; | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
$http_accept_language ~ ^(en|de|zh)