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

Side by Side Diff: modules/web/templates/site.erb

Issue 5451980818350080: Web server config: redirect canonical URLs to language-specific versions (Closed)
Patch Set: Fixed a mistake Created Dec. 12, 2013, 8:11 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 server { 1 server
2 {
2 listen 80 default_server; 3 listen 80 default_server;
3 listen [::]:80 default_server; 4 listen [::]:80 default_server;
4 server_name '<%= vhost %>'; 5 server_name '<%= vhost %>';
5 6
6 location / { 7 location /
8 {
7 rewrite (.*) https://<%= vhost %>$1 permanent; 9 rewrite (.*) https://<%= vhost %>$1 permanent;
8 } 10 }
9 } 11 }
10 12
11 server { 13 server
14 {
12 listen 443 ssl default_server; 15 listen 443 ssl default_server;
13 listen [::]:443 ssl default_server; 16 listen [::]:443 ssl default_server;
14 ssl_certificate sites-available/adblockplus.org_sslcert.pem; 17 ssl_certificate sites-available/adblockplus.org_sslcert.pem;
15 ssl_certificate_key sites-available/adblockplus.org_sslcert.key; 18 ssl_certificate_key sites-available/adblockplus.org_sslcert.key;
16 19
17 server_name '<%= vhost %>'; 20 server_name '<%= vhost %>';
18 21
19 expires 1d; 22 expires 1d;
20 23
21 root /var/www/<%= vhost %>; 24 root /var/www/<%= vhost %>;
22 index index; 25 index index;
23 default_type text/html; 26 default_type text/html;
27
28 # Match Accept-Language header against available languages
29
30 set $preferredLang "";
31 if ($http_accept_language ~ ^(\w\w)-(\w\w)\b)
32 {
33 set $preferrredLang $1_$2;
34 }
35 if (!-f $document_root/$preferredLang/index)
36 {
37 set $preferredLang "";
38 }
39
40 set $temp "$preferredLang|$http_accept_language";
41 if ($temp ~ ^\|(\w\w)\b)
42 {
43 set $preferredLang $1;
44 }
45 if (!-f $document_root/$preferredLang/index)
46 {
47 set $preferredLang "";
48 }
49
50 if ($preferredLang = "")
51 {
52 set $preferredLang "en";
53 }
54
55 # Always redirect server root
56
57 rewrite ^/$ /$preferredLang/ last;
58
59 # Don't do anything if requested file exists
60
61 if (-f $request_filename)
62 {
63 break;
64 }
65 if (-d $request_filename)
66 {
67 break;
68 }
69
70 # Redirect canonical URLs to language-specific versions
71
72 set $canonical $uri;
73 if ($canonical ~ ^(.*?)\?)
74 {
75 set $canonical $1;
76 }
77
78 if (-f $document_root/$preferredLang$canonical)
79 {
80 rewrite ^ /$preferredLang$canonical last;
81 }
82 if (-f $document_root/en$canonical)
83 {
84 rewrite ^ /en$canonical last;
85 }
24 } 86 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld