问题原文
原帖链接 · Hugo Marques · CC BY-SA 3.0
I have an app that was renamed and I want Haproxy to redirect to the correct path while preserving the request parameters
This is what I have:
acl old_name path_dir -i /old_name
http-request set-path /new_name/%[query] if old_name
I want it to change from
www.site.com/old_name/Default.aspx?Id=123
to
www.site.com/new_name/Default.aspx?Id=123 but this is not working.
已采纳解答
原帖链接 · Flint · CC BY-SA 4.0
With HAProxy 1.5 : use a temporary header to build a new path from the existing one in the request and then directly perform a redirect
# Clean the request and remove any existing header named X-Rewrite
http-request del-header X-REWRITE
# Copy the full request URL into X-Rewrite unchanged
http-request add-header X-REWRITE %[url] if { path_beg /old_path }
# Change the X-REWRITE header to contain out new path
http-request replace-header X-REWRITE ^/old_path(/.*)?$ /new_path\1 if { hdr_cnt(X-REWRITE) gt 0 }
# Perform the 301 redirect
http-request redirect code 301 location http://%[hdr(host)]%[hdr(X-REWRITE)] if { hdr_cnt(X-REWRITE) gt 0 }
In HAProxy 1.6, use the regsub filter
http-request redirect code 301 location http://%[hdr(host)]%[url,regsub(^/old_path,/new_path,)] if { path_beg /old_path }
source among other useful configuration snippets
More information is available in the HAProxy documentation for the regsub keyword.
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
