def rewrite(self, url_info: URLInfo) -> URLInfo:
        '''Rewrite the given URL.'''
        if url_info.scheme not in ('http', 'https'):
            return url_info

        if self._session_id_enabled:
            url = '{scheme}://{authority}{path}?{query}#{fragment}'.format(
                scheme=url_info.scheme,
                authority=url_info.authority,
                path=strip_path_session_id(url_info.path),
                query=strip_query_session_id(url_info.query),
                fragment=url_info.fragment,
            )
            url_info = parse_url_or_log(url) or url_info

        if self._hash_fragment_enabled and url_info.fragment.startswith('!'):
            if url_info.query:
                url = '{}&_escaped_fragment_={}'.format(url_info.url,
                                                        url_info.fragment[1:])
            else:
                url = '{}?_escaped_fragment_={}'.format(url_info.url,
                                                        url_info.fragment[1:])

            url_info = parse_url_or_log(url) or url_info

        return url_info
Rewrite the given URL.