From 68f1746d4180dbceb01083e668b93b4724501c3e Mon Sep 17 00:00:00 2001
From: jurgenhaas <juergen@paragon-es.de>
Date: Tue, 17 May 2016 16:09:25 +0200
Subject: [PATCH] Support more sophisticated redirects

---
 templates/haproxy_cfg | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/templates/haproxy_cfg b/templates/haproxy_cfg
index 9d3f468..c4070e3 100644
--- a/templates/haproxy_cfg
+++ b/templates/haproxy_cfg
@@ -60,7 +60,12 @@ frontend http_in
   http-request deny if blockedagent
 {% for host in groups['all'] %}
 {% for redirect in hostvars[host].proxy_redirect|default([]) %}
-  redirect prefix {{ redirect.protocol|default('https') }}://{{redirect.to}} code 301 if { hdr(host) -i -n {{redirect.from}} }
+{% for from in redirect.from %}
+{% for path in redirect.paths|default([]) %}
+  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 %} }
+{% endfor %}
+  redirect prefix {{ redirect.protocol|default('https') }}://{{redirect.to}} code 301 if { hdr(host) -i -n {{from}} }
+{% endfor %}
 {% endfor %}
 {% if proxy_redirect_aliase %}
 {% for drupal in hostvars[host].drupal_settings|default([]) %}
@@ -104,7 +109,12 @@ frontend https_in_{{ cert.ip }}
   http-request deny if blockedagent
 {% for host in groups['all'] %}
 {% for redirect in hostvars[host].proxy_redirect|default([]) %}
-  redirect prefix {{ redirect.protocol|default('https') }}://{{redirect.to}} code 301 if { hdr(host) -i -n {{redirect.from}} }
+{% for from in redirect.from %}
+{% for path in redirect.paths|default([]) %}
+  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 %} }
+{% endfor %}
+  redirect prefix {{ redirect.protocol|default('https') }}://{{redirect.to}} code 301 if { hdr(host) -i -n {{from}} }
+{% endfor %}
 {% endfor %}
 {% if proxy_redirect_aliase %}
 {% for drupal in hostvars[host].drupal_settings|default([]) %}
-- 
GitLab