From a01d704e85e15800529e14cf8139b83e0da3543d Mon Sep 17 00:00:00 2001 From: Dominique Fournier Date: Thu, 12 Sep 2019 07:55:52 +0000 Subject: [PATCH] route : relative routes are now relative to site base and not relative to current directory. Due to bad coded crawlers and browser as they don't manage correctely the ../ in front of relative URL. git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@5473 bf3deb0d-5f1a-0410-827f-c0cc1f45334c --- route.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/route.php b/route.php index a6a8062..d0394ae 100644 --- a/route.php +++ b/route.php @@ -127,11 +127,29 @@ class route { // Calculate the root in relative $request = $this->requestURL (); + if (substr ($_SERVER["REQUEST_URI"], -1 * strlen ($request)) === $request) + { + $this->baseURL = substr ($_SERVER["REQUEST_URI"], 0, + strlen ($_SERVER["REQUEST_URI"]) - strlen ($request)); + } + elseif ($_SERVER["REQUEST_URI"] !== "") + { + $this->baseURL = $_SERVER["REQUEST_URI"]; + } + else + { + $this->baseURL = "/"; + } + /* + // This part was to get really relative to current directory (with ../) + // But it is not really well supported by the bad coded crawlers. So, the + // URL is now relative to base of URL $this->baseURL = str_repeat ("../", substr_count ($request, "/")). $this->baseURL; if ($this->baseURL === "") $this->baseURL = "./"; + */ } $this->baseURLmodule = $this->baseURL; // Only != NOT !== (cause : $this->module can be converted in string "0")