Request URI in PHP
<?php
// [PATH_INFO] => /test/page
// [REQUEST_URI] => /test/page?id=5&name=loadme
$requestUri = $_SERVER['PATH_INFO'];
// strip terminating slash for any uri path except for root '/'
if ($requestUri !== '/' && substr($requestUri, -1) === '/') {
$requestUri = substr($requestUri, 0, strlen($requestUri) - 1);
}
/**
* Retrieves the uri path after the domain name and index.php. For example http://www.example.com/index.php/home
* would return index.php/home.
*
* @return void Uri path after the domain name.
*/
private function processRequestUri()
{
$requestUri = $_SERVER['PATH_INFO'];
// strip terminating slash for any uri path except for root '/'
if ($requestUri !== '/' && substr($requestUri, -1) === '/') {
$requestUri = substr($requestUri, 0, strlen($requestUri) - 1);
}
return $requestUri;
}