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

Unified 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.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: modules/web/templates/site.erb
===================================================================
--- a/modules/web/templates/site.erb
+++ b/modules/web/templates/site.erb
@@ -1,24 +1,86 @@
-server {
+server
+{
listen 80 default_server;
listen [::]:80 default_server;
server_name '<%= vhost %>';
- location / {
+ location /
+ {
rewrite (.*) https://<%= vhost %>$1 permanent;
}
}
-server {
+server
+{
listen 443 ssl default_server;
listen [::]:443 ssl default_server;
ssl_certificate sites-available/adblockplus.org_sslcert.pem;
ssl_certificate_key sites-available/adblockplus.org_sslcert.key;
server_name '<%= vhost %>';
expires 1d;
root /var/www/<%= vhost %>;
index index;
default_type text/html;
+
+ # Match Accept-Language header against available languages
+
+ set $preferredLang "";
+ if ($http_accept_language ~ ^(\w\w)-(\w\w)\b)
+ {
+ set $preferrredLang $1_$2;
+ }
+ if (!-f $document_root/$preferredLang/index)
+ {
+ set $preferredLang "";
+ }
+
+ set $temp "$preferredLang|$http_accept_language";
+ if ($temp ~ ^\|(\w\w)\b)
+ {
+ set $preferredLang $1;
+ }
+ if (!-f $document_root/$preferredLang/index)
+ {
+ set $preferredLang "";
+ }
+
+ if ($preferredLang = "")
+ {
+ set $preferredLang "en";
+ }
+
+ # Always redirect server root
+
+ rewrite ^/$ /$preferredLang/ last;
+
+ # Don't do anything if requested file exists
+
+ if (-f $request_filename)
+ {
+ break;
+ }
+ if (-d $request_filename)
+ {
+ break;
+ }
+
+ # Redirect canonical URLs to language-specific versions
+
+ set $canonical $uri;
+ if ($canonical ~ ^(.*?)\?)
+ {
+ set $canonical $1;
+ }
+
+ if (-f $document_root/$preferredLang$canonical)
+ {
+ rewrite ^ /$preferredLang$canonical last;
+ }
+ if (-f $document_root/en$canonical)
+ {
+ rewrite ^ /en$canonical last;
+ }
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld