public static function makeRelative($url)
    {
        // Allow for the accidental inclusion whitespace and // in the URL
        $url = preg_replace('#([^:])//#', '\\1/', trim($url));

        // If using a real url, remove protocol / hostname / auth / port
        if (preg_match('#^(?<protocol>https?:)?//(?<hostpart>[^/]*)(?<url>(/.*)?)$#i', $url, $matches)) {
            $url = $matches['url'];
        }

        // Empty case
        if (trim($url, '\\/') === '') {
            return '';
        }

        // Remove base folder or url
        foreach ([self::publicFolder(), self::baseFolder(), self::baseURL()] as $base) {
            // Ensure single / doesn't break comparison (unless it would make base empty)
            $base = rtrim($base, '\\/') ?: $base;
            if (stripos($url, $base) === 0) {
                return ltrim(substr($url, strlen($base)), '\\/');
            }
        }

        // Nothing matched, fall back to returning the original URL
        return $url;
    }