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