Refactor URL parsing in index.php to improve query parameter handling and enhance routing logic
This commit is contained in:
11
index.php
11
index.php
@@ -92,7 +92,11 @@ if ( $request_uri != '' )
|
|||||||
}
|
}
|
||||||
|
|
||||||
// check routes
|
// check routes
|
||||||
$request_uri = ltrim( $_SERVER['REQUEST_URI'], '/' );
|
$parsed_url = parse_url($_SERVER['REQUEST_URI']);
|
||||||
|
$request_uri = ltrim($parsed_url['path'], '/');
|
||||||
|
$query_string = isset($parsed_url['query']) ? $parsed_url['query'] : '';
|
||||||
|
parse_str($query_string, $query_params);
|
||||||
|
|
||||||
if ($request_uri != '')
|
if ($request_uri != '')
|
||||||
{
|
{
|
||||||
$matched = false;
|
$matched = false;
|
||||||
@@ -109,7 +113,10 @@ if ( $request_uri != '' )
|
|||||||
$destination = preg_replace("#^" . $pattern . "#", $destination, $request_uri);
|
$destination = preg_replace("#^" . $pattern . "#", $destination, $request_uri);
|
||||||
|
|
||||||
// Parse the destination string to extract GET parameters
|
// Parse the destination string to extract GET parameters
|
||||||
parse_str(parse_url($destination, PHP_URL_QUERY), $_GET);
|
parse_str(parse_url($destination, PHP_URL_QUERY), $destination_params);
|
||||||
|
|
||||||
|
// Merge the destination params with query params from the URL
|
||||||
|
$_GET = array_merge($destination_params, $query_params);
|
||||||
|
|
||||||
$matched = true;
|
$matched = true;
|
||||||
break;
|
break;
|
||||||
|
|||||||
Reference in New Issue
Block a user