diff --git a/templates/haproxy_cfg.jinja2 b/templates/haproxy_cfg.jinja2
index 49d746a1edf9d65802b34743cd88dd8af31dfd77..12c16e713bddf8373f2cfa89805eff48d6f77df0 100644
--- a/templates/haproxy_cfg.jinja2
+++ b/templates/haproxy_cfg.jinja2
@@ -88,8 +88,8 @@ frontend http_in
 {% endif %}
 {% endif %}
 {% endfor %}
-{% if from != redirect.to or redirect.protocol|default('https') == 'https' %}
-  redirect prefix {{ redirect.protocol|default('https') }}://{{redirect.to}} code 301 if { {{ (from == ".") | ternary('hdr_sub', 'hdr') }}(host) -i -n {{ from }} }
+{% if (from != redirect.to or redirect.protocol|default('https') == 'https') and from != "." %}
+  redirect prefix {{ redirect.protocol|default('https') }}://{{redirect.to}} code 301 if { hdr(host) -i -n {{ from }} }
 {% endif %}
 {% endfor %}
 {% endfor %}
@@ -198,8 +198,8 @@ frontend https_in_{{ cert.ip }}
 {% endif %}
 {% endif %}
 {% endfor %}
-{% if from != redirect.to or redirect.protocol|default('https') != 'https' %}
-  redirect prefix {{ redirect.protocol|default('https') }}://{{redirect.to}} code 301 if { {{ (from == ".") | ternary('hdr_sub', 'hdr') }}(host) -i -n {{ from }} }
+{% if (from != redirect.to or redirect.protocol|default('https') != 'https') and from != "." %}
+  redirect prefix {{ redirect.protocol|default('https') }}://{{redirect.to}} code 301 if { hdr(host) -i -n {{ from }} }
 {% endif %}
 {% endfor %}
 {% endfor %}