Haproxy subdirectory backend to root path rewrite

haproxy

I have a haproxy with subdirectory app at backend.
For now I'm using redirect location from root path to subfolder.

But I want to replace/rewrite site url without subfolder.

For example:

Frontend: service.site.com
Backend: 1.2.3.4:8080/app1

I want to my back end looks like service.site.com without app1 service.site.com/app1 at end of URL

how can I do it with reqrep?

Haproxy 1.8

Best Answer

you could do

reqrep ^([^\ :]*)\ (.*) \1\ /app1\2

I added this on the backend, just before the server line

the first part is the method (GET / POST / ....) then the last part you do (.*) which means any url.

The target would be \1<space> (the method regex result, preserve the space in the request)

/app1 (your wished destination)

\2 would be everything that was in the url request, appended to your path