You need a check header (hdr in haproxy) value via ACL. Try it:

frontend header_front
    bind *:80
    mode http
    option forwardfor if-none
    acl demo_host_version hdr(X-DEMO-HOST-VERSION) -i test
    use_backend test_backend if demo_host_version
    default_backend prod_backend

backend test_backend
    ...

backend prod_backend
    ...

Test for you header:

    acl demo_host_version hdr(X-DEMO-HOST-VERSION) -i test
    use_backend test_backend if demo_host_version

The logic: IF X-DEMO-HOST-VERSION=test use test_backend ELSE use prod_backend


UPD: If u need acl for path in URL (example.com/test/):

    acl demo_host_path path_beg /test/
    use_backend test_backend if demo_host_path

If u need use a two ACL in if statement use it:

    acl demo_host_version hdr(X-DEMO-HOST-VERSION) -i test
    acl demo_host_path path_beg /test/
    use_backend test_backend if demo_host_path demo_host_version

UPD for check URL:

Subdomain check. If u domain test.example.com or test.abc.com, try it:

acl host_sub_domain hdr_beg(host) -i test

For full domain check, eg test.example.com, try it:

acl host_full_domain hdr(host) -i test.example.com

Source: https://stackoverflow.com/questions/58589331/haproxy-how-to-forward-traffic-to-backend-by-a-matching-header