From 74d9b41e53b799c75171ab61351ebc8aff4bec6b Mon Sep 17 00:00:00 2001
From: Nathaniel Catchpole <catch@35733.no-reply.drupal.org>
Date: Mon, 29 Jan 2018 13:11:52 +0000
Subject: [PATCH] Issue #2929198 by alexpott: .ht.router.php does not support
 update.php

---
 .ht.router.php | 28 ++++++++++++++++++++++------
 1 file changed, 22 insertions(+), 6 deletions(-)

diff --git a/.ht.router.php b/.ht.router.php
index 4086277e926b..3da80a17f2ba 100644
--- a/.ht.router.php
+++ b/.ht.router.php
@@ -30,10 +30,26 @@
   return FALSE;
 }
 
-// The use of a router script means that a number of $_SERVER variables have to
-// be updated to point to the index-file.
-$index_file_absolute = $_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . 'index.php';
-$index_file_relative = DIRECTORY_SEPARATOR . 'index.php';
+// Work around the PHP bug.
+$path = $url['path'];
+$script = 'index.php';
+if (strpos($path, '.php') !== FALSE) {
+  // Work backwards through the path to check if a script exists. Otherwise
+  // fallback to index.php.
+  do {
+    $path = dirname($path);
+    if (preg_match('/\.php$/', $path) && is_file('.' . $path)) {
+      // Discovered that the path contains an existing PHP file. Use that as the
+      // script to include.
+      $script = ltrim($path, '/');
+      break;
+    }
+  } while ($path !== '/' && $path !== '.');
+}
+
+// Update $_SERVER variables to point to the correct index-file.
+$index_file_absolute = $_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . $script;
+$index_file_relative = DIRECTORY_SEPARATOR . $script;
 
 // SCRIPT_FILENAME will point to the router script itself, it should point to
 // the full path of index.php.
@@ -45,5 +61,5 @@
 $_SERVER['SCRIPT_NAME'] = $index_file_relative;
 $_SERVER['PHP_SELF'] = $index_file_relative;
 
-// Require the main index.php and let core take over.
-require $index_file_absolute;
+// Require the script and let core take over.
+require $_SERVER['SCRIPT_FILENAME'];
-- 
GitLab