| Left: | ||
| Right: |
| OLD | NEW |
|---|---|
| (Empty) | |
| 1 # Puppet: <%= @title %> | |
| 2 | |
| 3 root /var/www/<%= @domain %>; | |
| 4 index index; | |
| 5 default_type text/html; | |
| 6 charset utf-8; | |
| 7 | |
| 8 set $index_page "index"; | |
| 9 | |
| 10 <% if @custom_config %> | |
| 11 <%= @custom_config %> | |
| 12 <% end %> | |
| 13 | |
| 14 location / | |
| 15 { | |
| 16 expires 1d; | |
| 17 | |
| 18 # Redirect server/language root | |
| 19 | |
| 20 rewrite ^/$ /$index_page last; | |
| 21 rewrite ^/(\w\w(_\w\w)?)$ /$1/ permanent; | |
| 22 rewrite ^/(\w\w(_\w\w)?)/$ /$1/$index_page last; | |
| 23 | |
| 24 # Match Accept-Language header against available languages | |
| 25 | |
| 26 set $lang en; | |
|
mathias
2018/04/05 01:12:31
Abbreviation without any reason? https://www.youtu
f.lopez
2018/04/10 02:45:40
Acknowledged.
| |
| 27 set $region ""; | |
| 28 | |
| 29 if ($http_accept_language ~ ^(\w\w)\b) | |
| 30 { | |
| 31 set lang $1; | |
| 32 } | |
| 33 if ($http_accept_language ~ ^\w\w-(\w\w)\b) | |
| 34 { | |
| 35 set $region $1; | |
| 36 } | |
| 37 | |
| 38 if ($arg_fb_locale ~ ^(\w\w)_(\w\w)$) | |
| 39 { | |
| 40 set $lang $1; | |
| 41 set $region $2; | |
| 42 } | |
| 43 | |
| 44 # Redirect canonical URLs to language-specific versions | |
| 45 | |
| 46 if (-e "$document_root/${preferredLang}_$preferredRegion$uri") | |
| 47 { | |
| 48 rewrite ^(.*) /${lang}_$region last; | |
| 49 } | |
| 50 if (-e "$document_root/$preferredLang$uri") | |
| 51 { | |
| 52 rewrite ^(.*) /$lang$1 last; | |
| 53 } | |
| 54 if (-e "$document_root/en$uri") | |
| 55 { | |
| 56 rewrite ^(.*) /en$1 last; | |
| 57 } | |
| 58 } | |
| 59 | |
| 60 # Redirect language URIs if no translations are found for the requested page | |
| 61 | |
| 62 location ~ ^/([a-z][a-z]\_[A-Z][A-Z])(/.+) | |
| 63 { | |
| 64 if (!-e "$document_root$uri") | |
| 65 { | |
| 66 # if there is no language+region translation, try parent language URI | |
| 67 # example /es_MX/page -> /es/page | |
| 68 rewrite ^/([a-z][a-z])\_([A-Z][A-Z])(/.+) /$1$3 redirect; | |
| 69 } | |
| 70 } | |
| 71 | |
| 72 location ~ ^/([a-z][a-z])(/.+) | |
| 73 { | |
| 74 if (!-e "$document_root$uri") | |
| 75 { | |
| 76 # if there is no language translation, try canonical page for default langua ge | |
| 77 # example /es/page -> /page | |
| 78 rewrite ^/([a-z][a-z])(/.+) $2 redirect; | |
| 79 } | |
| 80 } | |
| OLD | NEW |