# Redirect scheme with regex?

**URL:** <https://discourse.haproxy.org/t/redirect-scheme-with-regex/226>\
**Category:** Help!\
**Created:** [April 19, 2016, 8:54am UTC](https://discourse.haproxy.org/t/redirect-scheme-with-regex/226 "2016-04-19T08:54:46Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mr.proxy](https://avatars.discourse-cdn.com/v4/letter/m/13edae/32.png) [@mr.proxy](https://discourse.haproxy.org/u/mr.proxy)\
**Post date:** [April 19, 2016, 8:54am UTC](https://discourse.haproxy.org/t/redirect-scheme-with-regex/226/1 "2016-04-19T08:54:46Z")

</div>

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](http://x.foobar.com) host. We need this since we also have a few customers that do not use SSL (like [x.otherdomain.net](http://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?

---

<div class="post-metadata">

**Author:** ![lukastribus](https://avatars.discourse-cdn.com/v4/letter/l/7ea924/32.png) [@lukastribus](https://discourse.haproxy.org/u/lukastribus)\
**Post date:** [April 19, 2016, 4:28pm UTC](https://discourse.haproxy.org/t/redirect-scheme-with-regex/226/2 "2016-04-19T16:28:08Z")

</div>

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`

---

<div class="post-metadata">

**Author:** ![Baptiste](https://avatars.discourse-cdn.com/v4/letter/b/cab0a1/32.png) [@Baptiste](https://discourse.haproxy.org/u/Baptiste)\
**Post date:** [April 23, 2016, 9:50pm UTC](https://discourse.haproxy.org/t/redirect-scheme-with-regex/226/3 "2016-04-23T21:50:17Z")

</div>

I’d better suggest:

```
hdr_dom(host) -m end .foobar.com
```
