# Trying to rewrite www tot non www HAproxy 3

**URL:** https://discourse.haproxy.org/t/trying-to-rewrite-www-tot-non-www-haproxy-3/11599
**Category:** Help!
**Created:** [February 5, 2025, 3:39pm UTC](https://discourse.haproxy.org/t/trying-to-rewrite-www-tot-non-www-haproxy-3/11599 "2025-02-05T15:39:45Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![Wininja](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.haproxy.org/wininja/32/2394_2.png) [@Wininja](https://discourse.haproxy.org/u/Wininja)
#### Post date: [February 5, 2025, 3:39pm UTC](https://discourse.haproxy.org/t/trying-to-rewrite-www-tot-non-www-haproxy-3/11599/1 "2025-02-05T15:39:45Z")

</div>

Hi,

I used to run HAProxy 1.9 and recently updated to 3.0.8 but I can’t get redirection from [www.domain.com](http://www.domain.com) to [domain.com](http://domain.com), which was working on 1.9.

My config on HAproxy 3 looks as follows:

frontend http-https  
bind \*:80  
bind \*:443 ssl crt-list /etc/haproxy/certs/certificate-list.txt strict-sni  
http-request return status 200 content-type text/plain lf-string “%[path,field(-1,/)].${ACCOUNT\_THUMBPRINT}\n” if { path\_beg ‘/.well-known/acme-challenge/’ }  
mode http

```
http-request redirect scheme https code 301 if !{ ssl_fc }

acl vdsverhuur_acl hdr(host) -i vdsverhuur.be
use_backend vdsverhuur if vdsverhuur_acl

acl www-vdsverhuur_acl hdr(host) -i www.vdsverhuur.be
use_backend vdsverhuur if www-vdsverhuur_acl

```

backend vdsverhuur  
mode http  
#balance roundrobin  
server verzamel01 172.16.0.12:80 check  
option forwardfor  
http-request set-header X-Forwarded-Port %[dst\_port]  
http-request add-header X-Forwarded-Proto https if { ssl\_fc }

I have been Googling fo 2 days now but I can’t find anything that works. Yny ideas to put me in the right direction?

Thanks,  
Rene

---

<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: [February 5, 2025, 4:03pm UTC](https://discourse.haproxy.org/t/trying-to-rewrite-www-tot-non-www-haproxy-3/11599/2 "2025-02-05T16:03:07Z")

</div>

You want to redirect to `https://vdsverhuur.be` if there is a match for Host header `www.vdsverhuur.be`, this would be:

```
http-request redirect prefix https://vdsverhuur.be if { hdr_dom(host) -i www.vdsverhuur.be }

```

---

<div class="post-metadata">

### Author: ![Wininja](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.haproxy.org/wininja/32/2394_2.png) [@Wininja](https://discourse.haproxy.org/u/Wininja)
#### Post date: [February 5, 2025, 4:52pm UTC](https://discourse.haproxy.org/t/trying-to-rewrite-www-tot-non-www-haproxy-3/11599/3 "2025-02-05T16:52:35Z")

</div>

Hi Lukas, thanks for your quick reply!  
I already tried that before and copied your line 100% into my running config, tested the config → all ok, restarted HAproxy but I still get the same error:

# This site can’t be reached

The web page at **[https://www.vdsverhuur.be/](https://www.vdsverhuur.be/)** might be temporarily down or it may have moved permanently to a new web address.

ERR\_SSL\_UNRECOGNIZED\_NAME\_ALERT

I just don’t see what I am missing here.

---

<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: [February 5, 2025, 5:16pm UTC](https://discourse.haproxy.org/t/trying-to-rewrite-www-tot-non-www-haproxy-3/11599/4 "2025-02-05T17:16:35Z")

</div>

On order for the redirect to work you need to allow connections to `www.vdsverhuur.be`, otherwise a redirect cannot be performed because the connection doesn’t even establish.

This means that the certificate needs to cover this hostname (currently it only covers the apex) and if your crt-list also restricts hostnames then you need to allow this hostname as well.

---

<div class="post-metadata">

### Author: ![Wininja](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.haproxy.org/wininja/32/2394_2.png) [@Wininja](https://discourse.haproxy.org/u/Wininja)
#### Post date: [February 5, 2025, 6:01pm UTC](https://discourse.haproxy.org/t/trying-to-rewrite-www-tot-non-www-haproxy-3/11599/5 "2025-02-05T18:01:33Z")

</div>

Ahhh, you mean either use a wildcard or use two certificates, one for www and one for just the apex?

---

<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: [February 5, 2025, 6:09pm UTC](https://discourse.haproxy.org/t/trying-to-rewrite-www-tot-non-www-haproxy-3/11599/6 "2025-02-05T18:09:25Z")

</div>

No, a wildcard or a secondary certificate is not required.

Just generate a certificate that is valid for both `www.vdsverhuur.be` and `vdsverhuur.be`.

You had this already until the last certificate update, the certificate generated on Dec 31st and older dates was valid for both hostnames:

> **[crt.sh | 16302191733](https://crt.sh/?id=16302191733)**
>
> Free CT Log Certificate Search Tool from Sectigo (formerly Comodo CA)

Only the last certificate created on January 19th had `www.vdsverhuur.be` removed and is valid only for `vdsverhuur.be`

---

<div class="post-metadata">

### Author: ![Wininja](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.haproxy.org/wininja/32/2394_2.png) [@Wininja](https://discourse.haproxy.org/u/Wininja)
#### Post date: [February 5, 2025, 8:37pm UTC](https://discourse.haproxy.org/t/trying-to-rewrite-www-tot-non-www-haproxy-3/11599/7 "2025-02-05T20:37:58Z")

</div>

Sir, you are awesome! That was exactly the problem. When I read your answer I thought: can I be that stupid? Clearly I am that stupid.

Thank you so much for your help!
