public static function getNormalizedUrl(Url $url)
    {
        $scheme = $url->getScheme();
        $host   = $url->getHost();
        $port   = $url->getPort();
        $path   = $url->getPath();

        // no port for 80 (http) and 443 (https)
        if ((($port == 80 || empty($port)) && strcasecmp($scheme, 'http') == 0) || (($port == 443 || empty($port)) && strcasecmp($scheme, 'https') == 0)) {
            $normalizedUrl = $scheme . '://' . $host . $path;
        } else {
            if (!empty($port)) {
                $normalizedUrl = $scheme . '://' . $host . ':' . $port . $path;
            } else {
                throw new RuntimeException('No port specified');
            }
        }

        return strtolower($normalizedUrl);
    }