Struggling to redirect one non-www domain to www over ssl

I am trying to redirect one domain behind my HAProxy load balancer from non-www to www prefix in Rancher over SSL. All the other redirections are working fine. example.com is being redirected to https://www.example. But https://example.com is not being redirected to https://www.example.com.

Here is my config in Rancher:

frontend 80
acl lepath path_beg -i /.well-known/acme-challenge
redirect scheme https code 301 if !{ hdr(host) -i example.com } !lepath !{ ssl_fc }
redirect prefix https://www.example.com code 301 if  { hdr(host) -i example.com } !lepath
redirect prefix https://www.example.com code 301 if  { hdr(host) -i www.example.com } !lepath !{ ssl_fc}

I am fairly new to HAProxy. I have gone through a lot of documentation but none of the configs are working here. Can someone help me out with it?

example.com -> https://www.example.com
www.example.com -> https://www.example.com
http://example.com -> https://www.example.com
http://www.example.com -> https://www.example.com
https://example.com -> https://www.example.com (Not working)

Share the entire configuration please.

This is the entire Custom config I have in the Rancher dashboard.

Then I won’t be able to help you, this forum is about haproxy, not rancher, we need to know how haproxy is configured.