Bladeren bron

fixing routing bug

Medowar 1 maand geleden
bovenliggende
commit
b886368f79
3 gewijzigde bestanden met toevoegingen van 14 en 10 verwijderingen
  1. 2 2
      .htaccess
  2. 1 1
      config/config.ini
  3. 11 7
      system/includes/dispatch.php

+ 2 - 2
.htaccess

@@ -2,7 +2,7 @@
 Options -Indexes
 
 # Make HTMLy handle any 404 errors.
-ErrorDocument 404 /index.php
+ErrorDocument 404 /blog/index.php
 
 # Set the default handler.
 DirectoryIndex index.php
@@ -90,7 +90,7 @@ DirectoryIndex index.php
 
 # Pass all requests not referring directly to files in the filesystem to index.php.
   RewriteCond %{REQUEST_FILENAME} !-f
-  RewriteCond %{REQUEST_FILENAME} !-d 
+  RewriteCond %{REQUEST_FILENAME} !-d
   RewriteRule ^ index.php [L]
 
 </IfModule>

+ 1 - 1
config/config.ini

@@ -1,5 +1,5 @@
 ; The URL of your blog.
-site.url = ""
+site.url = "https://www.medowar.de/blog"
 
 ; Your timezone
 timezone = "Europe/Berlin"

+ 11 - 7
system/includes/dispatch.php

@@ -24,7 +24,13 @@ function site_url()
 
 function generateSiteUrl()
 {
-    $dir = trim(dirname(substr($_SERVER["SCRIPT_FILENAME"], strlen($_SERVER["DOCUMENT_ROOT"]))), '/');
+    // Collapse repeated slashes and strip by prefix, not by string length: some
+    // hosts hand PHP a SCRIPT_FILENAME whose leading slash is doubled, which
+    // makes a length-based substr() slice one character into the real path.
+    $root = rtrim(preg_replace('#/+#', '/', $_SERVER["DOCUMENT_ROOT"]), '/');
+    $script = preg_replace('#/+#', '/', $_SERVER["SCRIPT_FILENAME"]);
+    $relative = strpos($script, $root . '/') === 0 ? substr($script, strlen($root)) : $script;
+    $dir = trim(dirname($relative), '/');
     if ($dir == '.' || $dir == '..') {
         $dir = '';
     }
@@ -41,12 +47,10 @@ function generateSiteUrl()
 
 function site_path()
 {
-    static $_path;
-
-    if (!$_path)
-        $_path = rtrim(parse_url(site_url(), PHP_URL_PATH), '/');
-
-    return $_path;
+    // Not cached in a static: session.php calls this during autoload, before
+    // config/config.ini is loaded, which would pin the auto-detected path and
+    // make [site.url] ineffective for routing.
+    return rtrim(parse_url(site_url(), PHP_URL_PATH), '/');
 }
 
 function theme_path()