2017-07-21 30 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部分作爲練習(但它看起來確定)。