From 683f211d5927098f0d233af10c480bf0cb5979ff Mon Sep 17 00:00:00 2001 From: jurgenhaas <juergen@paragon-es.de> Date: Thu, 27 Oct 2016 13:53:47 +0200 Subject: [PATCH] ansible-inventories/arocom#180 Support regex for redirects --- templates/haproxy_cfg | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/templates/haproxy_cfg b/templates/haproxy_cfg index 46cf9c8..02fa5df 100644 --- a/templates/haproxy_cfg +++ b/templates/haproxy_cfg @@ -78,8 +78,12 @@ frontend http_in {% for from in redirect.from %} {% for path in redirect.paths|default([]) %} {% if not path.deny|default(false) %} +{% if path.regex is defined and path.from is defined %} + http-request redirect code 301 location %[capture.req.uri,regsub({{path.regex}},)] if { hdr(host) -i -n {{from}} } { path_beg /{{path.from}} } +{% else %} redirect location {{ redirect.protocol|default('https') }}://{{redirect.to}}/{{path.to|default('')}} code 301 if { hdr(host) -i -n {{from}}{% if path.from is defined %} } { {{path.exact|default(false)|ternary('path','path_beg')}} /{{path.from}}{% endif %} } {% endif %} +{% endif %} {% endfor %} {% if from != redirect.to or redirect.protocol|default('https') == 'https' %} redirect prefix {{ redirect.protocol|default('https') }}://{{redirect.to}} code 301 if { hdr(host) -i -n {{from}} } @@ -156,8 +160,12 @@ frontend https_in_{{ cert.ip }} {% for from in redirect.from %} {% for path in redirect.paths|default([]) %} {% if not path.deny|default(false) %} +{% if path.regex is defined and path.from is defined %} + http-request redirect code 301 location %[capture.req.uri,regsub({{path.regex}},)] if { hdr(host) -i -n {{from}} } { path_beg /{{path.from}} } +{% else %} redirect location {{ redirect.protocol|default('https') }}://{{redirect.to}}/{{path.to|default('')}} code 301 if { hdr(host) -i -n {{from}}{% if path.from is defined %} } { {{path.exact|default(false)|ternary('path','path_beg')}} /{{path.from}}{% endif %} } {% endif %} +{% endif %} {% endfor %} {% if from != redirect.to or redirect.protocol|default('https') != 'https' %} redirect prefix {{ redirect.protocol|default('https') }}://{{redirect.to}} code 301 if { hdr(host) -i -n {{from}} } -- GitLab