You can use maps to make it work.
This is perfectly outlined in a post on the HAProxy.com blog. They're mapping based on the
Host header, but it would be trivial to change the config to work for the URL.
One extra benefit here is that you can dynamically add and remove mapping entries using the
http-[request|response] [set-map|del-map] keywords, or via the admin socket.
Changes made with
http-[request|response]or via the socket aren't persisted between reboots, so you'd want to have some out of band process to update the map file at the same time, but that's another question all together.
Assuming you have a backend for each server, and given a map file called
/etc/haproxy/items.map with these contents:
You would do something like this in your frontend:
If you have both servers in the same backend, you'd write an ACL in the front-end that catches all the items (
acl items path_beg /items), send them to the backend (
use_backend servers if items) and replace the
use_backend line from the frontend with appropriately if-claused
use_server lines in the backend.