From 26e048cc88d2fdbdb3ccb122261cbd67363f62a0 Mon Sep 17 00:00:00 2001 From: SteamPixel Date: Fri, 15 May 2020 11:38:43 +0200 Subject: [PATCH] Bugfix: Setup with subfolder works fine but doesn't match base path #23 --- src/Steampixel/Route.php | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/src/Steampixel/Route.php b/src/Steampixel/Route.php index f1485ef..48760d5 100644 --- a/src/Steampixel/Route.php +++ b/src/Steampixel/Route.php @@ -31,18 +31,31 @@ class Route { self::$methodNotAllowed = $function; } - public static function run($basepath = '/', $case_matters = false, $trailing_slash_matters = false, $multimatch = false) { + public static function run($basepath = '', $case_matters = false, $trailing_slash_matters = false, $multimatch = false) { + + // The basepath never needs a trailing slash + // Because the trailing slash will be added using the route expressions + $basepath = rtrim($basepath, '/'); + // Parse current URL $parsed_url = parse_url($_SERVER['REQUEST_URI']); - if (isset($parsed_url['path']) && $parsed_url['path'] != '/') { - if ($trailing_slash_matters) { - $path = $parsed_url['path']; - } else { - $path = rtrim($parsed_url['path'], '/'); - } - } else { - $path = '/'; + $path = '/'; + + // If there is a path available + if (isset($parsed_url['path'])) { + // If the trailing slash matters + if ($trailing_slash_matters) { + $path = $parsed_url['path']; + } else { + // If the path is not equal to the base path (including a trailing slash) + if($basepath.'/'!=$parsed_url['path']) { + // Cut the trailing slash away because it does not matters + $path = rtrim($parsed_url['path'], '/'); + } else { + $path = $parsed_url['path']; + } + } } // Get current request method