From 13a28c66f4839966ee612a666458e321faa976ee Mon Sep 17 00:00:00 2001
From: jurgenhaas <juergen@paragon-es.de>
Date: Mon, 26 Sep 2016 10:33:53 +0200
Subject: [PATCH] Make sure http-request always comes before the first redirect

---
 templates/haproxy_cfg | 22 ++++++++++++++++++++--
 1 file changed, 20 insertions(+), 2 deletions(-)

diff --git a/templates/haproxy_cfg b/templates/haproxy_cfg
index cb58244..747e2b2 100644
--- a/templates/haproxy_cfg
+++ b/templates/haproxy_cfg
@@ -68,7 +68,16 @@ frontend http_in
 {% 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_beg /{{path.from}}{% endif %} }
-{% else %}
+{% endif %}
+{% endfor %}
+{% endfor %}
+{% endfor %}
+{% endfor %}
+{% for host in groups['all'] %}
+{% for redirect in hostvars[host].proxy_redirect|default([]) %}
+{% for from in redirect.from %}
+{% for path in redirect.paths|default([]) %}
+{% if not path.deny|default(false) %}
   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_beg /{{path.from}}{% endif %} }
 {% endif %}
 {% endfor %}
@@ -135,7 +144,16 @@ frontend https_in_{{ cert.ip }}
 {% 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_beg /{{path.from}}{% endif %} }
-{% else %}
+{% endif %}
+{% endfor %}
+{% endfor %}
+{% endfor %}
+{% endfor %}
+{% for host in groups['all'] %}
+{% for redirect in hostvars[host].proxy_redirect|default([]) %}
+{% for from in redirect.from %}
+{% for path in redirect.paths|default([]) %}
+{% if not path.deny|default(false) %}
   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_beg /{{path.from}}{% endif %} }
 {% endif %}
 {% endfor %}
-- 
GitLab