This commit is contained in:
Bruno Rybársky 2024-01-16 21:20:20 +01:00
parent 6c1f4b6a9d
commit 77ec0423fb

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