HAProxy with multiple backends without conditions

I would like to use HAProxy to forward an inbound request to two servers, an old one and a new one, depending on which one is up and running, or randomly if both of them are up.

If the request hits the new server I also need a request rewrite with a special path (hence the http-request below):

frontend myservice
   bind:1111
   use_backend back-a
   use_backend back-b

backend back-a
   server  back-0     hostname_old:2222 check

backend back-b
   http-request set-path /special-path/%[path]
   server  back-1     hostname_new:443 check-ssl ssl verify none

The above does not work. The request is always forwarded to whichever backend is listed first: and if that’s not available I get an error.

Any suggestions?

All the examples I’ve seen of use_backend are followed by an “if”, but I don’t need any special condition, could that be the issue?

Many thanks!

here is a simple example, you can setup some rules or acls in frontend
in this example requests are forwarded to hostname_new if path beginns with /new (use_backend) or defaults to lbwww. in lbwww you set up which backend servers are available. in this example the new host will get more requests than old host (weight).

frontend www
    bind 12.34.56.78:80
    acl is_new path_beg /new
    use_backend new if is_new
    default_backend lbwww

backend lbwww
     server old     hostname_old:2222 maxconn 100 check weight 5
     server new     hostname_new:443  maxconn 100 check-ssl ssl verify none weight 10

backend new
     server new     hostname_new:443  maxconn 100 check-ssl ssl verify none