Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Delta Between Two Patch Sets: modules/web/templates/site.conf.erb

Issue 29537689: #3299 - Add URI redirect for missing translations (Closed) Base URL: https://hg1/infrastructure
Left Patch Set: try language if no translation for region Created Sept. 7, 2017, 8:36 a.m.
Right Patch Set: fix brackets and improve commit message Created Sept. 11, 2017, 8:51 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « no previous file | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 root /var/www/<%= @vhost %>; 1 root /var/www/<%= @vhost %>;
2 index index; 2 index index;
3 default_type text/html; 3 default_type text/html;
4 charset utf-8; 4 charset utf-8;
5 5
6 set $index_page "index"; 6 set $index_page "index";
7 7
8 <% if @custom_config %> 8 <% if @custom_config %>
9 <%= @custom_config %> 9 <%= @custom_config %>
10 <% end %> 10 <% end %>
11 11
12 location / 12 location /
13 { 13 {
14 expires 1d; 14 expires 1d;
15
16 # Redirect server/language root
17
18 rewrite ^/$ /$index_page last;
19 rewrite ^/(\w\w(_\w\w)?)$ /$1/ permanent;
20 rewrite ^/(\w\w(_\w\w)?)/$ /$1/$index_page last;
15 21
16 # Match Accept-Language header against available languages 22 # Match Accept-Language header against available languages
17 23
18 set $preferredLang en; 24 set $preferredLang en;
19 set $preferredRegion ""; 25 set $preferredRegion "";
20 if ($http_accept_language ~ ^(\w\w)\b) 26 if ($http_accept_language ~ ^(\w\w)\b)
21 { 27 {
22 set $preferredLang $1; 28 set $preferredLang $1;
23 } 29 }
24 if ($http_accept_language ~ ^\w\w-(\w\w)\b) 30 if ($http_accept_language ~ ^\w\w-(\w\w)\b)
(...skipping 14 matching lines...) Expand all
39 rewrite ^(.*) /${preferredLang}_$preferredRegion$1 last; 45 rewrite ^(.*) /${preferredLang}_$preferredRegion$1 last;
40 } 46 }
41 if (-e "$document_root/$preferredLang$uri") 47 if (-e "$document_root/$preferredLang$uri")
42 { 48 {
43 rewrite ^(.*) /$preferredLang$1 last; 49 rewrite ^(.*) /$preferredLang$1 last;
44 } 50 }
45 if (-e "$document_root/en$uri") 51 if (-e "$document_root/en$uri")
46 { 52 {
47 rewrite ^(.*) /en$1 last; 53 rewrite ^(.*) /en$1 last;
48 } 54 }
49
50 # Redirect server/language root
51
52 rewrite ^/$ /$index_page last;
53 rewrite ^/(\w\w(_\w\w)?)$ /$1/ permanent;
54 rewrite ^/(\w\w(_\w\w)?)/$ /$1/$index_page last;
55 } 55 }
56 56
57 # http://hub.eyeo.com/issues/3299 Redirect missing translations to default 57 # Redirect language URIs if no translations are found for the requested page
58 location ~ ^/([a-z][a-z]\_[A-Z][A-Z])(/.+) { 58
59 location ~ ^/([a-z][a-z]\_[A-Z][A-Z])(/.+)
60 {
59 if (!-e "$document_root$uri") 61 if (!-e "$document_root$uri")
60 { 62 {
61 » » # if there is no /es_Mx/page, redirect to /es/page instead: 63 # if there is no language+region translation, try parent language URI
62 » » rewrite ^/([a-z][a-z])\_([A-Z][A-Z])(/.+) /$1$3 redirect; 64 # example /es_MX/page -> /es/page
65 rewrite ^/([a-z][a-z])\_([A-Z][A-Z])(/.+) /$1$3 redirect;
63 } 66 }
64 } 67 }
65 68
66 location ~ ^/([a-z][a-z])(/.+) { 69 location ~ ^/([a-z][a-z])(/.+)
70 {
67 if (!-e "$document_root$uri") 71 if (!-e "$document_root$uri")
68 { 72 {
69 # if there is no /es/page, redirect to /page instead: 73 # if there is no language translation, try canonical page for default langua ge
74 # example /es/page -> /page
70 rewrite ^/([a-z][a-z])(/.+) $2 redirect; 75 rewrite ^/([a-z][a-z])(/.+) $2 redirect;
71 } 76 }
72 } 77 }
73 78
74 <% if @multiplexer_locations %> 79 <% if @multiplexer_locations %>
75 <% @multiplexer_locations.each do |location| %> 80 <% @multiplexer_locations.each do |location| %>
76 location <%= location %> 81 location <%= location %>
77 { 82 {
78 fastcgi_pass unix:/tmp/multiplexer-fastcgi.sock; 83 fastcgi_pass unix:/tmp/multiplexer-fastcgi.sock;
79 include /etc/nginx/fastcgi_params; 84 include /etc/nginx/fastcgi_params;
80 } 85 }
81 <% end %> 86 <% end %>
82 <% end %> 87 <% end %>
LEFTRIGHT
« no previous file | no next file » | Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Toggle Comments ('s')

Powered by Google App Engine
This is Rietveld