0

I am trying to redirect a path e.g. www.something.com/apple/pie to www.something.com/tickets/pie-details but also have some exceptions e.g. www.something.com/apple/helloworld does not get redirected to www.something.com/tickets/helloworld-details

This is what I have tried but doesn't work:

if (req.url ~ "^/apple/.*" && req.url != "^/apple/helloworld") {
    set req.url = "^/tickets/.*-details";
    error 701 req.url;
}
Raymond Ly
  • 42
  • 4

2 Answers2

1

https://info.varnish-software.com/blog/rewriting-urls-with-varnish-redirection

as an example (straight from the post):

sub vcl_recv {
    if (req.http.host != "www.varnish-software.com") {
        set req.http.location = "https://www.varnish-software.com/";
        return(synth(301));
    }
}
sub vcl_synth {
    if (resp.status == 301 || resp.status == 302) {
        set resp.http.location = req.http.location;
        return (deliver);
    }
}

you also need to write req.http.location properly. From what I understand, you want something like:

sub vcl_recv {
    if (req.url ~ "^/apple/.*" && req.url != "^/apple/helloworld") {
        set req.http.location = "/tickets + req.url + "-details";
        return(synth(301));
    }
}
0

I think it would be better to do a regex substitution.

if (req.url ~ "^/apple/.*" && req.url != "^/apple/helloworld") {
  set req.url = regsub(req.url, "^/apple/", "/tickets/");
  error 701 req.url;
}
Carlochess
  • 676
  • 1
  • 8
  • 22