diff --git a/classes/Factory/ViewFactory.php b/classes/Factory/ViewFactory.php index 591369dd..1b9fe6c2 100644 --- a/classes/Factory/ViewFactory.php +++ b/classes/Factory/ViewFactory.php @@ -37,6 +37,25 @@ private static function getCanonicalUrl(Request $request): string ->withScheme('https'); } + /** + * @param Uri $uri + * @return Uri + */ + private static function cleanBasePath(Uri $uri): Uri + { + $basePath = $uri->getBasePath(); + if (str_ends_with($basePath, 'index.php')) { + /* + * 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)); + } + + return $uri; + } + /** * Create Smarty view object. * @@ -76,6 +95,8 @@ public static function create(ContainerInterface $container, Request $request = /** @var LocaleManager $localeManager */ $localeManager = $container->get('locale'); + $uri = self::cleanBasePath($uri); + $smartyPlugins = new SmartyPlugins($container->get('router'), $uri->withUserInfo('')); $view->registerPlugin('function', 'path_for', [$smartyPlugins, 'pathFor']); $view->registerPlugin('function', 'base_url', [$smartyPlugins, 'baseUrl']); diff --git a/index.php b/index.php index 112fb7dd..0ca2302a 100644 --- a/index.php +++ b/index.php @@ -5,11 +5,6 @@ use Alltube\App; use Alltube\ErrorHandler; -if (isset($_SERVER['REQUEST_URI']) && strpos($_SERVER['REQUEST_URI'], '/index.php') !== false) { - header('Location: ' . str_ireplace('/index.php', '/', $_SERVER['REQUEST_URI'])); - die; -} - try { // Create app. $app = new App(); diff --git a/templates/inc/logo.tpl b/templates/inc/logo.tpl index b1da44f3..47b70b35 100644 --- a/templates/inc/logo.tpl +++ b/templates/inc/logo.tpl @@ -1,5 +1,5 @@

- + {$config->appName}