HA Proxy forwards based on URL

So for those of you that come across this and have similar issues, the fix was painfull simple (always the way).
Here are the steps I took to diagnose the issue as well as the fix so anyone in the same boat has the full picture:

  1. Add this line to catch the header requests in the frontend section with issues. In my case, I only had one frontend as I’m using HA Proxy to intercept all requests and look for one specific URL in the header then send it to a specific server. All non matches to another server. This string below will tell HA Proxy to capture the header requests. This will be used for logging.
    http-request capture req.hdr(Host) len 30

  2. Change your log-format line in the defaults to:
    log-format "%[capture.req.hdr(0)] %{+Q}[capture.req.hdr(1)]"

  3. Restart the ha-proxy server (sudo service haproxy restart) and tail the logs. For me, I saw the following:
    Jun 2 15:16:28 ha-proxy haproxy[13885]: 148.252.133.21:40846 [02/Jun/2020:15:16:28.915] default_frontend be_nginx/be_nginx 0/0/1/1/2 304 169 - - ---- 1/1/0/0/0 0/0 {rds.mydomain.com:81} "GET / HTTP/1.1"

So from that, the error was clear. As I was using:
use_backend be_rds if { hdr(Host) -i rds.mydomain.com } in the frontend, the entire hostname was attempting to be matched rather than if I had used: hdr_beg(host) to only match the host name (everything before the .)

Probably seems simple to those of you that have been using HA Proxy for sometime for for those of us new to it, I don’t think so. All guides I’ve found do not do a good job of explaining why, more a “copy and paste this”.

So a simple change to the use_backend be_rds if { hdr(Host) -i rds.mydomain.com } line, to instead read use_backend be_rds if { hdr(Host) -i rds.mydomain.com:81 } fixed the issue.

Hope it helps others stuck in a similar situation.