Modify link to handle servers with odd configurations

This commit is contained in:
Mike Koch 2017-11-07 21:48:38 -05:00
parent 443d4ac1f3
commit 30dcb113ae
No known key found for this signature in database
GPG Key ID: 9BA5D7F8391455ED

View File

@ -50,7 +50,17 @@ class Link
if ( !empty ( $_SERVER['PATH_INFO'] ) ) { if ( !empty ( $_SERVER['PATH_INFO'] ) ) {
$path = $_SERVER['PATH_INFO']; $path = $_SERVER['PATH_INFO'];
} else if ( !empty ( $_SERVER['REQUEST_URI'] ) ) { } else if ( !empty ( $_SERVER['REQUEST_URI'] ) ) {
$path = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH); $parts = explode('/', $_SERVER['REQUEST_URI']);
$startingIndex = -1;
for ($i = count($parts) - 1; $i > -1 && $startingIndex === -1; $i--) {
if ($parts[$i] === 'index.php' || $parts[$i] === 'api') {
$startingIndex = $i + 1;
}
}
$path = '';
for ($i = $startingIndex; $i < count($parts); $i++) {
$path .= "/{$parts[$i]}";
}
} }
if ( isset($routes[$path] ) ) { if ( isset($routes[$path] ) ) {