How to redirect changing path in the backend

I have Portainer running at portainer_agent:9000 in my Swarm. I would like to access http://myserver.com/portainer to get portainer, but I can’t find how to accomplish that.
The “http-request set-path” I’m using at backend is almost working, but it’s not quite there yet.
So the question: How to get the path /portainer/anything redirected to /anything at the backend.

Here is my haproxy.conf snippet:

frontend http-in
    bind *:80
    
    acl is_portainer path_beg /portainer
    use_backend portainer if is_portainer

backend portainer
    balance leastconn
    mode http
    http-request set-path "%[path,regsub(^/portainer,/,)]" if { path_beg /portainer }
    server portainer portainer_agent:9000 resolvers docker_resolver resolve-prefer ipv4

Thank you.

You don’t, because all the links in the payload would have to be rewritten as well, redirects from the backend, cookies, etc. This is a never-ending story and haproxy cannot rewrite some of it.

Instead, use a dedicated Hostname, so you don’t have to deal with path, cookie, payload rewriting, etc.