如何使用Varnish添加重定向异常? [英] How to add redirect exceptions using Varnish?

查看:78
本文介绍了如何使用Varnish添加重定向异常?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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;
}

推荐答案

作为一个例子(直接从帖子中):

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);
    }
}

您还需要正确编写req.http.location.据我了解,您想要类似的东西:

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));
    }
}

这篇关于如何使用Varnish添加重定向异常?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆