remove www. from host and redirect with 301 on haproxy

If you have a lot of domains on single haproxy frontend and only want domains without www for SEO reasons, you can remove the www. with this configuration

# add header on every incoming request with www
http-request add-header X-Host-Redirect yes if { hdr_beg(host) -i www. }
# math header
acl host_redirect hdr_cnt(X-Host-Redirect) eq 1
# change host header if X-Host-Redirect is present
reqirep ^Host:\ www.(.*)$ Host:\ \1 if host_redirect
# redirect with schema http
redirect code 301 scheme http if host_redirect

Deja un comentario

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *