2017-07-21 116 views
0

我在nginx的HAProxy的重定向变量不工作规则路径元素

rewrite ^/rty/(.*)$ example.com/$1?lead 

我试图做同样的HAProxy的

acl uri_lc path_reg ^/lc/(.*)$ 
http-request redirect location example.com/$1?lead code 301 if uri_lc 

以下重定向规则重定向工作,但路径元素变量$ 1似乎不适用于haproxy。

回答

0

您可以使用http-request'sset-pathset-query来重写请求。

# remove /rty part 
http-request set-path %[path,regsub(/rty,,g)] 

# set query string 
http-request set-query lead 

# redirect - this is actually a pretty tricky way to redirect 
# to the modified request without giving path 
http-request redirect scheme http code 301 

# empty prefix could be use as well 
# http-request redirect prefix ' ' code 301 

在1.6以前的版本中,您可以使用reqrep来模拟类似的功能。例如:

reqrep ^([^\ :]*)\ /rty/(.*)  \1\ /\2 
redirect scheme http code 301 

注:我跳过acl部分作为练习(但它看起来确定)。