From 45583defa81286c10d4844e6e177f24db764a038 Mon Sep 17 00:00:00 2001
From: memtkmcc <memtkmcc@92646.no-reply.drupal.org>
Date: Sat, 14 Jan 2017 02:49:41 +0100
Subject: [PATCH] Issue #2843473 by memtkmcc: Nginx: Use Drupal 8 friendly
 rewrites

---
 .../Config/Nginx/Inc/vhost_include.tpl.php         | 33 ++++++++++++++++++----
 http/Provision/Config/Nginx/subdir.tpl.php         | 29 ++++++++++++++++---
 2 files changed, 52 insertions(+), 10 deletions(-)

diff --git a/http/Provision/Config/Nginx/Inc/vhost_include.tpl.php b/http/Provision/Config/Nginx/Inc/vhost_include.tpl.php
index 476fb07..bb98776 100644
--- a/http/Provision/Config/Nginx/Inc/vhost_include.tpl.php
+++ b/http/Provision/Config/Nginx/Inc/vhost_include.tpl.php
@@ -1245,7 +1245,17 @@ location @drupal {
     return 418;
   }
 <?php endif; ?>
-  rewrite ^/(.*)$  /index.php?q=$1 last;
+  ###
+  ### For Drupal >= 7
+  ###
+  if ($sent_http_x_generator) {
+    add_header X-Info-Gen "Modern";
+    rewrite ^ /index.php?$query_string last;
+  }
+  ###
+  ### For Drupal <= 6
+  ###
+  rewrite ^/(.*)$ /index.php?q=$1 last;
 }
 
 <?php if ($nginx_config_mode == 'extended'): ?>
@@ -1254,11 +1264,11 @@ location @drupal {
 ###
 location @nobots {
   ###
-  ### Support for Accelerated Mobile Pages (AMP).
+  ### Support for Accelerated Mobile Pages (AMP) when bots are redirected below
   ###
-  if ( $query_string ~ "^amp$" ) {
-    rewrite ^/(.*)$  /index.php?q=$1 last;
-  }
+  # if ( $query_string ~ "^amp$" ) {
+  #  rewrite ^/(.*)$  /index.php?q=$1 last;
+  # }
 
   ###
   ### Send all known bots to $args free URLs (optional)
@@ -1274,7 +1284,18 @@ location @nobots {
   if ( $args ~* "=PHP[A-Z0-9]{8}-" ) {
     return 404;
   }
-  rewrite ^/(.*)$  /index.php?q=$1 last;
+
+  ###
+  ### For Drupal >= 7
+  ###
+  if ($sent_http_x_generator) {
+    add_header X-Info-Gen "Modern";
+    rewrite ^ /index.php?$query_string last;
+  }
+  ###
+  ### For Drupal <= 6
+  ###
+  rewrite ^/(.*)$ /index.php?q=$1 last;
 }
 
 ###
diff --git a/http/Provision/Config/Nginx/subdir.tpl.php b/http/Provision/Config/Nginx/subdir.tpl.php
index e979fdf..fb28ceb 100644
--- a/http/Provision/Config/Nginx/subdir.tpl.php
+++ b/http/Provision/Config/Nginx/subdir.tpl.php
@@ -1199,6 +1199,16 @@ location @drupal_<?php print $subdir_loc; ?> {
     return 418;
   }
 <?php endif; ?>
+  ###
+  ### For Drupal >= 7
+  ###
+  if ($sent_http_x_generator) {
+    add_header X-Info-Gen "Modern";
+    rewrite ^ /<?php print $subdir; ?>/index.php?$query_string last;
+  }
+  ###
+  ### For Drupal <= 6
+  ###
   rewrite ^/<?php print $subdir; ?>/(.*)$  /<?php print $subdir; ?>/index.php?q=$1 last;
 }
 
@@ -1208,11 +1218,11 @@ location @drupal_<?php print $subdir_loc; ?> {
 ###
 location @nobots_<?php print $subdir_loc; ?> {
   ###
-  ### Support for Accelerated Mobile Pages (AMP).
+  ### Support for Accelerated Mobile Pages (AMP) when bots are redirected below
   ###
-  if ( $query_string ~ "^amp$" ) {
-    rewrite ^/<?php print $subdir; ?>/(.*)$  /<?php print $subdir; ?>/index.php?q=$1 last;
-  }
+  # if ( $query_string ~ "^amp$" ) {
+  #   rewrite ^/<?php print $subdir; ?>/(.*)$  /<?php print $subdir; ?>/index.php?q=$1 last;
+  # }
 
   ###
   ### Send all known bots to $args free URLs (optional)
@@ -1228,6 +1238,17 @@ location @nobots_<?php print $subdir_loc; ?> {
   if ( $args ~* "=PHP[A-Z0-9]{8}-" ) {
     return 404;
   }
+
+  ###
+  ### For Drupal >= 7
+  ###
+  if ($sent_http_x_generator) {
+    add_header X-Info-Gen "Modern";
+    rewrite ^ /<?php print $subdir; ?>/index.php?$query_string last;
+  }
+  ###
+  ### For Drupal <= 6
+  ###
   rewrite ^/<?php print $subdir; ?>/(.*)$  /<?php print $subdir; ?>/index.php?q=$1 last;
 }
 
-- 
2.10.1 (Apple Git-78)

