From 77ec0423fbb4cb87b9cac778e939b95b2e430746 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bruno=20Ryb=C3=A1rsky?= Date: Tue, 16 Jan 2024 21:20:20 +0100 Subject: [PATCH] test --- lib/routing.php | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/lib/routing.php b/lib/routing.php index b80be39..fd6b09b 100644 --- a/lib/routing.php +++ b/lib/routing.php @@ -28,15 +28,27 @@ function initRouter(){ $routerRequest["page_name"] = basename($_SERVER["QUERY_STRING"]); - if (empty($routerRequest["page_name"])){ + if (empty($routerRequest["subdomain"])) { + // Subdomain is missing + $needsRedirect = true; + } elseif (empty($routerRequest["page_name"])) { + // Page name is empty $needsRedirect = true; } } if ($needsRedirect) { $redirectAddress = implode('.', $routerRequest["requestAddress"]); - header("Location: " . $routerRequest["protocol"] . $redirectAddress . "/" . $routerConfig["default_page"]); + if (empty($routerRequest["page_name"])) { + // Redirect without page name + header("Location: " . $routerRequest["protocol"] . $redirectAddress . "/"); + } else { + // Redirect with default page name + header("Location: " . $routerRequest["protocol"] . $redirectAddress . "/" . $routerConfig["default_page"]); + } + exit; // Ensure that the script stops execution after the redirect header } + return !$needsRedirect; }