public function getRoot()
    {
        $requestUri = $this->getRequestUri();
        $pathInfo = $this->getPathInfo();

        // remove query string from REQUEST_URI, if set
        if (false !== $qPos = mb_strpos($requestUri, '?')) {
            // has query string
            $requestUri = mb_substr($requestUri, 0, $qPos + 1);
        }

        // remove PATH_INFO from REQUEST_URI, if set
        if (false !== $pPos = mb_strrpos($requestUri, $pathInfo)) {
            // has PATH_INFO
            $requestUri = mb_substr($requestUri, 0, $pPos + 1);
        }

        return $requestUri;
    }
public function getRoot()
    {
        $requestUri = $this->getRequestUri();
        $pathInfo = $this->getPathInfo();

        // remove query string from REQUEST_URI, if set
        if (false !== $qPos = mb_strpos($requestUri, '?')) {
            // has query string
            $requestUri = mb_substr($requestUri, 0, $qPos + 1);
        }

        // remove PATH_INFO from REQUEST_URI, if set
        if (false !== $pPos = mb_strrpos($requestUri, $pathInfo)) {
            // has PATH_INFO
            $requestUri = mb_substr($requestUri, 0, $pPos + 1);
        }

        return $requestUri;
    }
public function getRoot ( ) { $ requestUri = $ this -> getRequestUri ( ) ; $ pathInfo = $ this -> getPathInfo ( ) ; // remove query string from REQUEST_URI, if set if ( false !== $ qPos = mb_strpos ( $ requestUri , '?' ) ) { // has query string $ requestUri = mb_substr ( $ requestUri , 0 , $ qPos + 1 ) ; } // remove PATH_INFO from REQUEST_URI, if set if ( false !== $ pPos = mb_strrpos ( $ requestUri , $ pathInfo ) ) { // has PATH_INFO $ requestUri = mb_substr ( $ requestUri , 0 , $ pPos + 1 ) ; } return $ requestUri ; }
Get the REQUEST_URI without PATH_INFO and QUERY_STRING, taking server
rewriting in consideration.

Example (without URL rewriting):
https://www.example.org/foo/index.php/bar?a=b will return:
'/foo/index.php'

Example (with URL rewriting to index.php):
https://www.example.org/foo/bar?a=b will return:
'/foo'

Example (with URL rewriting to index.php without sub folder):
https://www.example.org/bar?a=b will return:
''
Get the REQUEST_URI without PATH_INFO and QUERY_STRING taking server rewriting in consideration .