HaProxy as reverse proxy for ArcGIS

Hi

I am trying to configure a reverse proxy to sit in front of an ArcGIS environment, link below from ESI’s documentation regarding reverse proxy config for reference.

The proxy will need to forward traffic to 2 separate backends depending on the path
For example
https://gis.domain.com/portal needs to be forwarded to ‘backend gisportal’
and
https://gis.domain.com/server needs to be forwarded to ‘backend gisserver’

This part I have working using the configuration below but both backends expect the path to be arcgis
For example
https://arcgis.test.local:7443/arcgis when forwarding to ‘backend gisportal’
and
https://arcgis.test.local:6443/arcgis when forwarding to ‘backend gisserver’

I have tried a few things with replace-path but can’t seem to figure it out.

Any help with this would be appreciated, thanks.

frontend 443
bind :80
mode http
bind :::443 v4v6 ssl crt gis.domain.com alpn h2,http/1.1

http-request redirect scheme https code 301 unless { ssl_fc }
acl letsencrypt-req path_beg /.well-known/acme-challenge/
use_backend letsencrypt if letsencrypt-req
acl portal_pathbeg path_beg -i /portal
acl server_pathbeg path_beg -i /server
acl hosts_gis hdr(host) -i gis.domain.com
use_backend gisportal if portal_pathbeg hosts_gis
use_backend gisserver if server_pathbeg hosts_gis
http-response set-header Strict-Transport-Security max-age=16000000;\ includeSubDomains;\ preload;

backend gisportal
mode http
http-response set-header X-Server %s
server arcgis.test.local:7443 192.168.3.33:7443 check ssl verify none

backend gisserver
mode http
http-request set-header Host gis.domain.co.uk

http-request replace-path /server /arcgis

http-request replace-path /server(arc)?(.*) /\2

http-request replace-path (/arcgis/)(.*)$ \1\2

server arcgis.test.local:6443 172.xxx.x.xx:6443 check ssl verify none

With the help of AI https://www.perplexity.ai
I think I have found a solution with the backend like this

backend gisportal
mode http
http-request set-header Host gis.domain.co.uk
# Store the original path
http-request set-var(txn.original_path) path
# Modify the path for the backend
http-request set-path /arcgis%[path,regsub(^/portal,)]
# Preserve original path in redirects
http-response replace-header Location (https?://[^/])(/portal.) \1%[var(txn.original_path)]
server arcgis.test.local:7443 172.xxx.xxx.xxx:7443 check ssl verify none

backend gisserver
mode http
http-request set-header Host gis.domain.co.uk
# Store the original path
http-request set-var(txn.original_path) path
# Modify the path for the backend
http-request set-path /arcgis%[path,regsub(^/server,)]
# Preserve original path in redirects
http-response replace-header Location (https?://[^/])(/server.) \1%[var(txn.original_path)]
server arcgis.test.local:6443 172.xxx.xxx.xxx:6443 check ssl verify none