HAProxy – 根据条件执行多个重写

我试图根据一些条件重写一个URI以及主机头。 这是我想要完成的一个例子:

我请求http://sub1.example.com/test/files/other

if hdr_beg(Host) sub1.example.com and path_beg /test rewrite host header to sub2.example.com rewrite URI to /files/other (in other words, remove test from the URI) 

最终的结果应该指向sub2.example.com/files/other而用户不知道。

我已经尝试了以下configuration:

 acl host_beg_sub1 hdr_beg(Host) sub1.example.com acl path_beg_test path_beg /test rewrite host header if host_beg_sub1 path_beg_test rewrite URI if host_beg_sub1 path_beg_test 

显然,这不能按预期工作,因为第二次重写不会在主机头被修改之后触发。

因为有其他stream量的URI可能以testing开始,所以我不能无条件重写。

提前致谢!

如果你想做一堆replace,你可能要考虑把它们放在后端。

 frontend acl host_beg_sub1 hdr_beg(Host) sub1.example.com acl path_beg_test path_beg /test use_backend sub2redirect if host_beg_sub1 path_beg_test backend reqirep ^Host:\ sub1.example.com Host:\ sub2.example.com reqirep ...url rewriting server ...