Skip to content

Instantly share code, notes, and snippets.

@PiBa-NL
Last active June 22, 2022 02:25
Show Gist options
  • Star 16 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save PiBa-NL/8ad6c222354cbd7a5af5 to your computer and use it in GitHub Desktop.
Save PiBa-NL/8ad6c222354cbd7a5af5 to your computer and use it in GitHub Desktop.
haproxy, remove /app after selecting backend
Code to change a request from / to /app1/
reqirep ^([^\ :]*)\ /(.*) \1\ /app1/\2
If urls in the response contain absolute urls it might be required to use this:
acl no_redir url_beg /app1/
reqirep ^([^\ :]*)\ /(.*) \1\ /app1/\2 if !no_redir
The code makes sure that the method and url-path behind the / stays the same. Which method you need exactly might depend on the application thats running.
For readability of the above how change a request from /app1/ to /app1/app1redir/
reqirep ^([^\ :]*)\ /app1/(.*) \1\ /app1/app1redir/\2
If those above dont work you might still be able to get a acceptable workaround by using a redirect:
acl no_redir url_beg /app1/
http-request redirect location http://%[req.hdr(Host)]/app1/ if !no_redir
@dalenoe
Copy link

dalenoe commented May 15, 2019

What version(s) of haproxy will this work with?

@L1so
Copy link

L1so commented Jun 22, 2022

What version(s) of haproxy will this work with?

Anything less than 2.1, because reqirep is deprecated in 2.1 onward

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment