public static function removeBasepath($uri, $path)
    {
        $uri = self::normalizePath(self::filterUri($uri));
        $basepath = (new HierarchicalPath($path))->withLeadingSlash();
        if ('/' === (string) $basepath) {
            return $uri;
        }

        $currentpath = $uri->getPath();
        if (0 !== strpos($currentpath, (string) $basepath)) {
            return $uri;
        }

        return $uri->withPath(
            (string) (new HierarchicalPath($currentpath))->withoutSegment(...range(0, count($basepath) - 1))
        );
    }