Skip to content

Commit e8d291e

Browse files
committed
nodejs.org: falling back to english when page hasn't been translated.
Refs nodejs/nodejs.org#490
1 parent dd2f493 commit e8d291e

File tree

1 file changed

+33
-1
lines changed

1 file changed

+33
-1
lines changed

setup/www/resources/config/nodejs.org

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,11 @@ server {
4040
default_type text/plain;
4141
index index.html;
4242

43+
error_page 404 @localized_404;
44+
4345
location / {
46+
try_files $uri $uri/ @english_fallback;
47+
4448
location ~ \.json$ {
4549
add_header access-control-allow-origin *;
4650
}
@@ -55,6 +59,19 @@ server {
5559
add_header access-control-allow-origin *;
5660
}
5761
}
62+
63+
# instead of serving a 404 page when a page hasn't been translated
64+
location @english_fallback {
65+
if ($uri ~* ^/(it|ko)/) {
66+
set $lang $1;
67+
}
68+
rewrite ^/(it|ko)/(.*)$ /en/$2;
69+
}
70+
71+
# serve a localized 404 page if we've got $lang set from @english_fallback
72+
location @localized_404 {
73+
try_files /$lang/404.html /en/404.html;
74+
}
5875
}
5976

6077
server {
@@ -192,7 +209,7 @@ server {
192209
gzip_disable "MSIE [1-6]\.";
193210
gzip_types text/plain text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript;
194211

195-
error_page 404 /en/404.html;
212+
error_page 404 @localized_404;
196213

197214
if ($host ~* ^www\.) {
198215
rewrite ^(.*)$ https://nodejs.org$1;
@@ -219,11 +236,26 @@ server {
219236
location / {
220237
rewrite ^/$ /en/ redirect;
221238

239+
try_files $uri $uri/ @english_fallback;
240+
222241
location ~ \.json$ {
223242
add_header access-control-allow-origin *;
224243
}
225244
}
226245

246+
# instead of serving a 404 page when a page hasn't been translated
247+
location @english_fallback {
248+
if ($uri ~* ^/(it|ko)/) {
249+
set $lang $1;
250+
}
251+
rewrite ^/(it|ko)/(.*)$ /en/$2;
252+
}
253+
254+
# serve a localized 404 page if we've got $lang set from @english_fallback
255+
location @localized_404 {
256+
try_files /$lang/404.html /en/404.html;
257+
}
258+
227259
location /download {
228260
alias /home/dist/nodejs;
229261
autoindex on;

0 commit comments

Comments
 (0)