From 335003774671c64736bbde6db8a6de9b2ac9cb06 Mon Sep 17 00:00:00 2001 From: jurgenhaas <juergen@paragon-es.de> Date: Mon, 13 Mar 2017 11:25:53 +0100 Subject: [PATCH] Implement more options for redirects --- templates/haproxy_cfg.jinja2 | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/templates/haproxy_cfg.jinja2 b/templates/haproxy_cfg.jinja2 index e6d6602..49d746a 100644 --- a/templates/haproxy_cfg.jinja2 +++ b/templates/haproxy_cfg.jinja2 @@ -68,10 +68,10 @@ frontend http_in {% for from in redirect.from %} {% for path in redirect.paths|default([]) %} {% if path.deny|default(false) %} - http-request deny if { hdr(host) -i -n {{from}}{% if path.from is defined %} } { {{path.exact|default(false)|ternary('path','path_beg')}} /{{path.from}}{% endif %} } + http-request deny if { {{ (from == ".") | ternary('hdr_sub', 'hdr') }}(host) -i -n {{ from }}{% if path.from is defined %} } { {{path.exact|default(false)|ternary('path','path_beg')}} /{{path.from}}{% endif %} } {% else %} {% 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}} } + http-request redirect code 301 location %[capture.req.uri,regsub({{path.regex}},)] if { {{ (from == ".") | ternary('hdr_sub', 'hdr') }}(host) -i -n {{ from }} } { path_beg /{{path.from}} } {% endif %} {% endif %} {% endfor %} @@ -84,12 +84,12 @@ frontend http_in {% for path in redirect.paths|default([]) %} {% if not path.deny|default(false) %} {% if path.regex is not defined or path.from is not defined %} - 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 %} } + redirect location {{ redirect.protocol|default('https') }}://{{redirect.to}}/{{path.to|default('')}}{% if path.append_path|default(false) %}%[path]{% endif %}{% if path.append_query is defined %}?{{ path.append_query }}{% endif %} code 301 if { {{ (from == ".") | ternary('hdr_sub', '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}} } + redirect prefix {{ redirect.protocol|default('https') }}://{{redirect.to}} code 301 if { {{ (from == ".") | ternary('hdr_sub', 'hdr') }}(host) -i -n {{ from }} } {% endif %} {% endfor %} {% endfor %} @@ -178,10 +178,10 @@ frontend https_in_{{ cert.ip }} {% for from in redirect.from %} {% for path in redirect.paths|default([]) %} {% if path.deny|default(false) %} - http-request deny if { hdr(host) -i -n {{from}}{% if path.from is defined %} } { {{path.exact|default(false)|ternary('path','path_beg')}} /{{path.from}}{% endif %} } + http-request deny if { {{ (from == ".") | ternary('hdr_sub', 'hdr') }}(host) -i -n {{ from }}{% if path.from is defined %} } { {{path.exact|default(false)|ternary('path','path_beg')}} /{{path.from}}{% endif %} } {% else %} {% 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}} } + http-request redirect code 301 location %[capture.req.uri,regsub({{path.regex}},)] if { {{ (from == ".") | ternary('hdr_sub', 'hdr') }}(host) -i -n {{ from }} } { path_beg /{{path.from}} } {% endif %} {% endif %} {% endfor %} @@ -194,12 +194,12 @@ frontend https_in_{{ cert.ip }} {% for path in redirect.paths|default([]) %} {% if not path.deny|default(false) %} {% if path.regex is not defined or path.from is not defined %} - 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 %} } + redirect location {{ redirect.protocol|default('https') }}://{{redirect.to}}/{{path.to|default('')}}{% if path.append_path|default(false) %}%[path]{% endif %}{% if path.append_query is defined %}?{{ path.append_query }}{% endif %} code 301 if { {{ (from == ".") | ternary('hdr_sub', '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}} } + redirect prefix {{ redirect.protocol|default('https') }}://{{redirect.to}} code 301 if { {{ (from == ".") | ternary('hdr_sub', 'hdr') }}(host) -i -n {{ from }} } {% endif %} {% endfor %} {% endfor %} -- GitLab