Redirect scheme with regex?


#1

I have tried to use regular expression, but without luck.

We have a SSL wildcard sertificate for *.foobar.com and which to add use a redirect like this:

redirect schema https if { hdr(host} -i ^.*\.foobar\.com } !{ ssl_fc }

but without luck. I ended up with a lot of lines like this:

redirect schema https if { hdr(host) -i a.foobar.com } !{ ssl_fc }

Which cause a lot of extra maintenance each time we add a new x.foobar.com host. We need this since we also have a few customers that do not use SSL (like x.otherdomain.net) and they shall not be redirected to use https.

Is there a way to make haproxy support wildecard with redirect as described above?


#2

Remove the ^ at the beginning of the regex, or it will never match a subdomain.

You don’t need regex for this though, this should suffice:
hdr(host) -m end .foobar.com


#3

I’d better suggest:

hdr_dom(host) -m end .foobar.com