我可以使用 Varnish 重新格式化我的 URL 参数吗

发布于 2024-09-15 05:35:36 字数 625 浏览 4 评论 0原文

我有一个相对简单的(我认为)用例,但我找不到任何有人这样做的例子。我们在两个不同的应用程序之前使用 Varnish 作为缓存和反向代理,并希望使两者之间的事情更加统一,因为它们都做类似的事情。我希望 Varnish 可以帮助重写 URL,如下所示。

用于分页的原始应用程序 URL(获取前 10 项):

http://myapplication.com/products/?startindex=1&endindex=10

所需 URL:

http://myapplication.com/products/?paginate=1:10

这只是一个示例(最复杂的示例,因为它结合了两个参数),但在所有情况下,参数的输入值都保持不变,只是参数名称将会改变。

另一个例子是:

http://myapplication.com/search/?query=something

到:

http://myapplication.com/search/?q=something

有谁有清漆的经验以及如何做到这一点?

谢谢

I have a relatively simple (I think) use-case but I can't find any examples where someone has done this. We are using Varnish as a cache and reverse proxy in front of two different applications and would like to make things a bit more unified across both as they both do similar things. I was hoping Varnish could help rewrite the URLs as shown below.

Original application URL for pagination (get first 10 items):

http://myapplication.com/products/?startindex=1&endindex=10

Desired URL:

http://myapplication.com/products/?paginate=1:10

This is just one example (the most complex because it combines two parameters), but in all cases the input values for the parameters stay the same, it is just that the parameter names will change.

Another example would be:

http://myapplication.com/search/?query=something

to:

http://myapplication.com/search/?q=something

Does anyone have any experience with varnish and how this could be done?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

半世晨晓 2024-09-22 05:35:37

显然你可以。答案是 regsub 是你的朋友。

例如:

if (req.url ~ "(.*)(id=)") {
        set req.url = regsub(req.url, "(feeds/[a-zA-Z]*/)(.*)([\?|&])(id=)([a-zA-Z0-9]*)(.*)", "\1\2\3byGuid=\5\6");
}

这会将传入的“id”参数转换为后端的“byGuid”参数。 t 还对 URL 字符串的其余部分做了很多事情,但基础知识就在那里。因此,如果有人想做类似的事情,这是一个很好的起点。

Apparently you can. The answer is that regsub is your friend.

For example:

if (req.url ~ "(.*)(id=)") {
        set req.url = regsub(req.url, "(feeds/[a-zA-Z]*/)(.*)([\?|&])(id=)([a-zA-Z0-9]*)(.*)", "\1\2\3byGuid=\5\6");
}

This will convert and incoming "id" parameter into a "byGuid" parameter on the backend. t also does a bunch of stuff with the rest of the URL string but the basics are there. SO if anyone wants to do something similar this is a good starting point.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文