URL Redirection in Varnish 4

In varnish 4, you can do 30x redirects using Synthetic responses. For example:

sub vcl_recv {

    if (req.http.host == "my.old.com") {
            return (synth(301, "http://another.url.1"));
    }

    if (req.http.host == "my.old2.com") {
            return (synth(302, "http://another.url.2"));
    }
}

sub vcl_synth {
    if (resp.status == 301 || resp.status == 302) {
        set resp.http.location = resp.reason;
        set resp.reason = "Moved";
        return (deliver);
    }
}

Comments