From dd583aaf8bd5f69a6adada203808bd55dea1d7a6 Mon Sep 17 00:00:00 2001
From: jurgenhaas <juergen@paragon-es.de>
Date: Wed, 23 May 2018 17:29:14 +0200
Subject: [PATCH] Support to omit the destination domain in redirects and
 default to the request domain Implement support for extra conditions in
 redirects

---
 templates/haproxy_cfg.jinja2 | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/templates/haproxy_cfg.jinja2 b/templates/haproxy_cfg.jinja2
index e59e2b2..c9f576c 100644
--- a/templates/haproxy_cfg.jinja2
+++ b/templates/haproxy_cfg.jinja2
@@ -104,12 +104,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 %}
-  http-request redirect code 301 location {{ redirect.protocol|default('https') }}://{{redirect.to}}/{{path.to|default('')}}{% if path.append_path|default(false) %}%[capture.req.uri]{% endif %}{% if path.append_query is defined %}?{{ path.append_query }}{% endif %} if !letsencrypt_challenge { {{ (from == ".") | ternary('hdr_sub', 'hdr') }}(host) -i -n {{ from }}{% if path.from is defined %} } { {{path.exact|default(false)|ternary('path /','path_reg ^/')}}{{path.from}}{% endif %} }
+  http-request redirect code 301 location {{ redirect.protocol|default('https') }}://{{redirect.to|default(from)}}/{{path.to|default('')}}{% if path.append_path|default(false) %}%[capture.req.uri]{% endif %}{% if path.append_query is defined %}?{{ path.append_query }}{% endif %} if !letsencrypt_challenge { {{ (from == ".") | ternary('hdr_sub', 'hdr') }}(host) -i -n {{ from }}{% if path.from is defined %} } { {{path.exact|default(false)|ternary('path /','path_reg ^/')}}{{path.from}}{% endif %}{% if path.condition is defined %} {{path.condition}}{% endif %} }
 {% endif %}
 {% endif %}
 {% endfor %}
-{% if (from != redirect.to or redirect.protocol|default('https') == 'https') and redirect.paths is not defined %}
-  redirect prefix {{ redirect.protocol|default('https') }}://{{redirect.to}} code 301 if !letsencrypt_challenge { hdr(host) -i -n {{ from }} }
+{% if (from != redirect.to|default(from) or redirect.protocol|default('https') == 'https') and redirect.paths is not defined %}
+  redirect prefix {{ redirect.protocol|default('https') }}://{{redirect.to|default(from)}} code 301 if !letsencrypt_challenge { hdr(host) -i -n {{ from }} }
 {% endif %}
 {% endfor %}
 {% endfor %}
@@ -233,12 +233,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 %}
-  http-request redirect code 301 location {{ redirect.protocol|default('https') }}://{{redirect.to}}/{{path.to|default('')}}{% if path.append_path|default(false) %}%[capture.req.uri]{% endif %}{% if path.append_query is defined %}?{{ path.append_query }}{% endif %} if { {{ (from == ".") | ternary('hdr_sub', 'hdr') }}(host) -i -n {{ from }}{% if path.from is defined %} } { {{path.exact|default(false)|ternary('path /','path_reg ^/')}}{{path.from}}{% endif %} }
+  http-request redirect code 301 location {{ redirect.protocol|default('https') }}://{{redirect.to|default(from)}}/{{path.to|default('')}}{% if path.append_path|default(false) %}%[capture.req.uri]{% endif %}{% if path.append_query is defined %}?{{ path.append_query }}{% endif %} if { {{ (from == ".") | ternary('hdr_sub', 'hdr') }}(host) -i -n {{ from }}{% if path.from is defined %} } { {{path.exact|default(false)|ternary('path /','path_reg ^/')}}{{path.from}}{% endif %}{% if path.condition is defined %} {{path.condition}}{% endif %} }
 {% endif %}
 {% endif %}
 {% endfor %}
-{% if (from != redirect.to or redirect.protocol|default('https') != 'https') and redirect.paths is not defined %}
-  redirect prefix {{ redirect.protocol|default('https') }}://{{redirect.to}} code 301 if { hdr(host) -i -n {{ from }} }
+{% if (from != redirect.to|default(from) or redirect.protocol|default('https') != 'https') and redirect.paths is not defined %}
+  redirect prefix {{ redirect.protocol|default('https') }}://{{redirect.to|default(from)}} code 301 if { hdr(host) -i -n {{ from }} }
 {% endif %}
 {% endfor %}
 {% endfor %}
-- 
GitLab