0

haproxy version 1.5.18

I want to redirect:

/document/(.*)/(.*)/somefile => /anotherPath/somefile

For example: redirect

/document/20181/20182/a_good_pic.jpg => /anotherPath/a_good_pic.jpg

How to do that with haproxy?

I retried follow the example for reqirep like:

# replace "/static/" with "/" at the beginning of any request path.
reqrep ^([^\ :]*)\ /static/(.*)     \1\ /\2

But my example has two parts in URL path that are different to the example, so I got confused.

Thanks!

r ne
  • 101
  • 1
  • 2
  • 1
    This is much easier in HAProxy 1.6 and later, where you have access to features like [`http-request set-path`](http://cbonte.github.io/haproxy-dconv/1.6/configuration.html#4-http-request) and a converter called [`regsub`](http://cbonte.github.io/haproxy-dconv/1.6/configuration.html#7.3.1-regsub). Also you are using the word *redirect* but you don't appear to actually want a redirect -- sending the browser the browser to a new URL with an HTTP `30X` response. Do you want a redirect? Or do you want to *rewrite the request* before sending it to the back-end? – Michael - sqlbot Jan 26 '19 at 04:03
  • Thanks. I will try HAProxy 1.6, if the IT people could upgrade it. Actually we don't care if it is a redirect or rewrite, as long as the last URL works for the user to download the required files. – r ne Jan 27 '19 at 08:44

0 Answers0