def METHOD_NAME(get_response):
    """
    Middleware to redirect access to any of the domains specified
    by the keys in settings.HOSTNAME_REDIRECTS to their corresponding
    values. Preserves the full path of the URL.
    For example, if settings.HOSTNAME_REDIRECTS is {'foo.com': 'bar.com'},
    then any accesses to http://foo.com/blah will be redirected to
    http://bar.com/blah.
    """
    def middleware(request):
        host = request.get_host()
        if host in settings.HOSTNAME_REDIRECTS:
            new_host = settings.HOSTNAME_REDIRECTS[host]
            path = request.get_full_path()
            return HttpResponseRedirect(f"{get_protocol()}://{new_host}{path}")
        return get_response(request)
    return middleware