diff --git a/route.php b/route.php index 9364d14..648a400 100644 --- a/route.php +++ b/route.php @@ -45,19 +45,29 @@ class route if (isset ($_SERVER["HTTPS"]) && $_SERVER["SERVER_PORT"] === "443") $port = ""; - if (isset ($_SERVER["SCRIPT_NAME"])) - $this->baseURL = dirname ($_SERVER["SCRIPT_NAME"]); + $this->baseURL = ""; if ($absolute === true) { + if (isset ($_SERVER["SCRIPT_NAME"])) + $this->baseURL = dirname ($_SERVER["SCRIPT_NAME"]); if (isset ($_SERVER["SERVER_NAME"])) $this->baseURL = "//".$_SERVER["SERVER_NAME"].$port.$this->baseURL; if (isset ($_SERVER["HTTPS"])) $this->baseURL = "https:".$this->baseURL; else $this->baseURL = "http:".$this->baseURL; + if (substr ($this->baseURL, -1) !== "/") + $this->baseURL .= "/"; + } + else + { + // Calculate the root in relative + $request = $this->requestURL (); + $root = dirname ($_SERVER["SCRIPT_NAME"]); + $requestdir = substr ($request, 1+strlen ($root)); + $this->baseURL = str_repeat ("../", + substr_count ($requestdir, "/")). $this->baseURL; } - if (substr ($this->baseURL, -1) !== "/") - $this->baseURL .= "/"; $this->baseURLmodule = $this->baseURL; // Only != NOT !== (cause : $this->module can be converted in string "0") if ($this->module != FALSE) @@ -302,6 +312,7 @@ file_put_contents ("/tmp/csrf.log", date ("Y-m-d H:i:s")." DELETE route->map ($r public function map ($route, $function) { $url = substr ($this->requestURL (), strlen ($this->baseURLmodule ())); + $url = substr ($this->requestURL (), 1+ strlen (dirname ($_SERVER["SCRIPT_NAME"]))); if ($this->debug) echo "$url "; if ($url === $route)