Add ability to create redirect

 add support use one backend for several URLs
 add section for frontend in README

Change-Id: I3ddef66b72f5681d08cef8a5042e7755591d3de7
diff --git a/README.rst b/README.rst
index 108398e..871f567 100644
--- a/README.rst
+++ b/README.rst
@@ -323,6 +323,44 @@
               port: 6379
               params: check inter 1s
 
+Frontend for routing between exists listeners via URL with SSL an redirects.
+You can use one backend for several URLs.
+
+.. code-block:: yaml
+
+  haproxy:
+    proxy:
+      listen:
+        service_proxy:
+          mode: http
+          balance: source
+          format: end
+          binds:
+           - address: ${_param:haproxy_bind_address}
+             port: 80
+             ssl: ${_param:haproxy_frontend_ssl}
+             ssl_port: 443
+          redirects:
+           - code: 301
+             location: domain.com/images
+             conditions:
+               - type: hdr_dom(host)
+                 condition: images.domain.com
+          acls:
+           - name: gerrit
+             conditions:
+               - type: hdr_dom(host)
+                 condition: gerrit.domain.com
+           - name: jenkins
+             conditions:
+               - type: hdr_dom(host)
+                 condition: jenkins.domain.com
+           - name: docker
+             backend: artifactroy
+             conditions:
+               - type: hdr_dom(host)
+                 condition: docker.domain.com
+
 Read more
 =========
 
diff --git a/haproxy/files/haproxy.cfg b/haproxy/files/haproxy.cfg
index 5ab108b..f2f6271 100644
--- a/haproxy/files/haproxy.cfg
+++ b/haproxy/files/haproxy.cfg
@@ -211,12 +211,17 @@
   bind {{ listen.binds[0].address }}:{{ listen.binds[0].ssl_port|default('443') }} {% if listen.binds[0].ssl.pem_file is defined %}ssl crt {{ listen.binds[0].ssl.pem_file }}{% else %}ssl crt /etc/haproxy/ssl/{{ listen_name }}{% endif %}
   redirect scheme https code 301 if !{ ssl_fc }
   {% endif %}
+  {%- for redirect in listen.get('redirects', []) %}
+  {%- for condition in redirect.get('conditions', []) %}
+  redirect {% if redirect.code is defined %} code {{ redirect.code }} {% endif %} location {{ redirect.location }} if { {{ condition.type }} {{ condition.condition }} }
+  {%- endfor %}
+  {%- endfor %}
   {%- for acl in listen.get('acls', []) %}
   {%- for condition in acl.get('conditions', []) %}
   acl {{ acl.name }} {{ condition.type }} {{ condition.condition }}
   {%- endfor %}
   {%- if listen_name == 'service_proxy' %}
-  use_backend {{ acl.name }} if {{ acl.name }}
+  use_backend {{ acl.backend|default(acl.name, true) }} if {{ acl.name }}
   {% else %}
   use_backend {{ acl.name }}-backend if {{ acl.name }}
   {% endif %}