def METHOD_NAME(url: str, domain: str, bucket: str, region: str, **kwargs) -> str:
    """
    Rewrites the url so that it can be forwarded to moto. Used for vhost-style and for any url that contains the region.
    For vhost style: removes the bucket-name from the host-name and adds it as path
    E.g. https://bucket.s3.localhost.localstack.cloud:4566 -> https://s3.localhost.localstack.cloud:4566/bucket
    E.g. https://bucket.s3.amazonaws.com -> https://s3.localhost.localstack.cloud:4566/bucket
    If the region is contained in the host-name we remove it (for now) as moto cannot handle the region correctly
    :param url: the original url
    :param domain: the domain name (anything after s3.<region>., may include a port)
    :param bucket: the bucket name
    :param region: the region name (includes the '.' at the end)
    :return: re-written url as string
    """
    splitted = urlsplit(url)
    if splitted.netloc.startswith(f"{bucket}."):
        netloc = splitted.netloc.replace(f"{bucket}.", "")
        path = f"{bucket}{splitted.path}"
    else:
        # we already have a path-style addressing, only need to remove the region
        netloc = splitted.netloc
        path = splitted.path
    # TODO region currently ignored
    if region:
        netloc = netloc.replace(f"{region}", "")
    # the user can specify whatever domain & port he wants in the Host header
    # we need to make sure we're redirecting the request to our edge URL, possibly s3.localhost.localstack.cloud
    host = domain
    edge_host = f"{LOCALHOST_HOSTNAME}:{config.get_edge_port_http()}"
    if host != edge_host:
        netloc = netloc.replace(host, edge_host)
    return urlunsplit((splitted.scheme, netloc, path, splitted.query, splitted.fragment))