如何使用Varnish添加重定向异常?

如何使用Varnish添加重定向异常?,varnish,varnish-vcl,fastly,Varnish,Varnish Vcl,Fastly,我正在尝试将路径(例如www.something.com/apple/pie)重定向到www.something.com/tickets/pie-details,但也有一些例外,例如。 www.something.com/apple/helloworld不会被重定向到www.something.com/tickets/helloworld-details 这是我尝试过但不起作用的方法: if (req.url ~ "^/apple/.*" && req.url != "^/app

我正在尝试将路径(例如www.something.com/apple/pie)重定向到www.something.com/tickets/pie-details,但也有一些例外,例如。 www.something.com/apple/helloworld不会被重定向到www.something.com/tickets/helloworld-details

这是我尝试过但不起作用的方法:

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

我认为最好用正则表达式替换

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

举个例子(直接从文章中):

您还需要正确地写入
req.http.location
。据我所知,你想要的是:

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