From 2afbfb4bf2e0680fc84c40df7543f2df4508dfc7 Mon Sep 17 00:00:00 2001 From: Pierre Rudloff Date: Sun, 20 Feb 2022 14:06:59 +0100 Subject: [PATCH] fixup! Don't redirect to REQUEST_URI when browsing to index.php Instead, we can make sure everything works correctly on index.php --- classes/Factory/ViewFactory.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/classes/Factory/ViewFactory.php b/classes/Factory/ViewFactory.php index 1b9fe6c..52715f4 100644 --- a/classes/Factory/ViewFactory.php +++ b/classes/Factory/ViewFactory.php @@ -45,12 +45,21 @@ class ViewFactory { $basePath = $uri->getBasePath(); if (str_ends_with($basePath, 'index.php')) { + $basePath = dirname($basePath); + if ($basePath == '/') { + /* + * Calling withBasePath('/') does nothing, + * we have to use an empty string instead. + */ + $basePath = ''; + } + /* * When the base path ends with index.php, * routing works correctly, but it breaks the URL of static assets using {base_url}. * So we alter the base path but only in the URI used by SmartyPlugins. */ - $uri = $uri->withBasePath(dirname($basePath)); + $uri = $uri->withBasePath($basePath); } return $uri;