-$path = $fullUri = urldecode($_SERVER['REQUEST_URI']);//with query string
-$qPos = strpos($fullUri, '?');
-if ($qPos !== false) {
- $path = substr($fullUri, 0, $qPos);
-}
+
+$requestUriNoQuery = explode('?', $_SERVER['REQUEST_URI'])[0];
+$path = $fullUri = urldecode($requestUriNoQuery);
+