Maybe have two cases:
For the (matched keyword) case, something like this: https://serverfault.com/questions/729232/reg-exp-for-url-in-haproxy
For the (random routing) case, something like: https://www.haproxy.com/blog/haproxy-configuration-basics-load-balance-your-servers
I am a little confused on your question, though. It sounds like you maybe want 3 cases? Can you try wording it differently?
Cool, I think that first link will work for you. Then you can just ‘redirect’ for the no-keyword case: https://www.haproxy.com/documentation/haproxy-configuration-tutorials/http-redirects/
Remember, SSL/HTTPS does encrypt the URL path, so if the final website requires HTTPS, your proxy will need to have its certificate trusted by your clients