Skip to content

Commit dec0e02

Browse files
committed
Update LIB-Route.php
Small fix for handling funky URLs such as http://site.com//FOO
1 parent 48cac15 commit dec0e02

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

core/lib/LIB-Route.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,20 @@ class Route extends Core {
99

1010
// (A) RUN URL ROUTING ENGINE
1111
function run () : void {
12-
// (A1) CLEAN CURRENT URL PATH
12+
// (A1) GET URL PATH SEGMENT
13+
$this->path = parse_url($_SERVER["REQUEST_URI"], PHP_URL_PATH);
14+
15+
// (A2) SPECIAL CASE
16+
// e.g. http://site.com//, http://site.com//XYZ
17+
if ($this->path == "") {
18+
$this->load("PAGE-404.php", 404);
19+
exit();
20+
}
21+
22+
// (A3) CLEAN CURRENT URL PATH
1323
// http://site.com/ > $this->path = "/"
1424
// http://site.com/hello/world/ > $this->path = "hello/world/"
15-
$this->path = parse_url($_SERVER["REQUEST_URI"], PHP_URL_PATH);
25+
$this->path = preg_replace("~/{2,}~", "/", $this->path);
1626
if (substr($this->path, 0, strlen(HOST_BASE_PATH)) == HOST_BASE_PATH) {
1727
$this->path = substr($this->path, strlen(HOST_BASE_PATH));
1828
}

0 commit comments

Comments
 (0)