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; }