Redirection with https

Hi,
Helps please.

I’m trying to configure redirection.
I would like to do that :

if client enters https://example.com it will be redirect to https:://www.site.com

My configuration is :
redirect prefix https://www.site.cm if { hdr(host) -i example.com }

But when the user enters https://example.com it’s redirect to the root folder.

How can i correct this issue ?

Thanks in advance !!

Share your complete configuration please?

My configuration

global
log /dev/log local0
log /dev/log local1 notice
chroot /var/lib/haproxy
stats socket /run/haproxy/admin.sock mode 660 level admin
stats timeout 30s
user haproxy
group haproxy
daemon

tune.ssl.default-dh-param 2048
maxconn 5000

# Default SSL material locations
ca-base /etc/ssl/certs
crt-base /etc/ssl/private

# Default ciphers to use on SSL-enabled listening sockets.
# For more information, see ciphers(1SSL). This list is from:
#  https://hynek.me/articles/hardening-your-web-servers-ssl-ciphers/
ssl-default-bind-ciphers ECDH+AESGCM:DH+AESGCM:ECDH+AES256:DH+AES256:ECDH+AES128:DH+AES:ECDH+3DES:DH+3DES:RSA+AESGCM:RSA+AES:RSA+3DES:!aNULL:!MD5:!DSS
ssl-default-bind-options no-sslv3

defaults
log global
mode http
option forwardfor
option http-server-close
option httplog
option dontlognull
timeout connect 5000
timeout client 50000
timeout server 50000
errorfile 400 /etc/haproxy/errors/400.http
errorfile 403 /etc/haproxy/errors/403.http
errorfile 408 /etc/haproxy/errors/408.http
errorfile 500 /etc/haproxy/errors/500.http
errorfile 502 /etc/haproxy/errors/502.http
errorfile 503 /etc/haproxy/errors/503.http
errorfile 504 /etc/haproxy/errors/504.http

frontend www-http
bind *:80
mode http
option httpclose
option forwardfor

redirect prefix https://www.site.cm if { hdr(host) -i www.example.com }
redirect prefix https://www.site.cm if { hdr(host) -i example.com }

frontend www-https
bind *:443 ssl crt /key.pem
mode http
option forwardfor
option httpclose
option http-server-close
reqadd X-Forwarded-Proto:\ https

redirect prefix https://www.site.cm if { hdr(host) -i www.example.com }
redirect prefix https://www.site.cm if { hdr(host) -i example.com }
 
 


default_backend defaultBackendServer

backend defaultBackendServer
mode http
redirect scheme http code 301 if !{ ssl_fc }
balance source
server SRV-WEB-1 192.168.2.13:80 check
server SRV-WEB-2 192.168.2.14:80 check

backend testBackend

mode http 
redirect scheme http code 301 if !{ ssl_fc }
balance source
acl no_redir url_beg   /test/test/
reqirep ^([^\ :]*)\ /(.*)     \1\ /test/test/\2 if !no_redir
server SRV-WEB-1 192.168.2.13:80 check
server SRV-WEB-2 192.168.2.14:80 check

listen stats
bind 192.168.2.16:1992
mode http
log global
maxconn 2
clitimeout 100s
srvtimeout 100s
contimeout 100s
timeout queue 100s
stats enable
stats hide-version
stats refresh 30s
stats show-node
stats auth admin:password
stats uri /haproxy?stats

I don’t see anything wrong with this configuration.

What do you see from a curl output?

curl -vv http://example.com
curl -vv http://www.example.com