Removing part of the URI

Hi All,

I would like to request help with the configuration of HAProxy. I am looking to offer a longer URL external and proxy it to internal services that only reference the last part.

I have a config like this (abbreviated to be easier to read):

frontend EXTERNAL
        acl redirect_to_service1 path_beg -i /service1/foo/APICALL
        use_backend INTERNAL-SERVICE1 if redirect_to_service1 

        acl redirect_to_service2 path_beg -i /service2/foo/APICALL
        use_backend INTERNAL-SERVICE2 if redirect_to_service2

        server NAME check
        http-request set-uri "%[path,regsub(/service1/foo/(.*),/\1)]" # was set-path
        server NAME check
        http-request set-uri "%[path,regsub(/service2/foo/(.*),/\1)]" # was set-path

Is anyone able to offer guidance or a solution on removing the /service2/foo or /service1/foo from the request sent to the backend only? The client will still request on those API.

Thanks in advance,

I think this should be:

http-request set-path %[path,regsub(/service1/foo/,/)]
1 Like

there my be an email arriving saying I’d tried it and it didn’t work. After sending I thought I’d double check and I was wrong, that has worked a treat thanks!


Hi Lukastribus,

You wouldn’t happen to know if the second part (foo in the example above) could be parsed out and added as a HTTP header?


Try something like this, before rewriting the path:

http-request set-header x-path "%[path,regsub(/[^/]+/,/)]"