On Fri, Aug 10, 2018 at 12:57 AM, Anthony Vuong <avu...@library.ucla.edu> wrote:
> Hello, > > I seem to possibly be missing the obvious here. But wondering if anyone > can shed some light. > > I'm trying to have different url paths be routed to different backends. > > frontend testdomain > bind 172.16.0.17:80 > bind 172.16.0.17:443 > mode http > acl redirectarchives path_beg -i /ua > > use_backend testbe if redirectarchives > # default_backend stageweb > > backend testbe > reqrep ^([^\ :]*)\ /ua/(.*) \1\ /\2 > balance leastconn > option forwardfor > server ext1 172.17.0.18:80 check port 80 > > I'm a bit confused on what the rewrite is doing. > > Scenario: > -> user goes to testdomain.com/ua > --> works > -> user goes to testdomain.com/ua/test/ > --> works > -> user goes to testdomain.com/ua/test > --> gets redirected to testdomain.com/test > > I know the URL rewrite is the culprit because commenting it out does not > exhibit the same behaviour. But I'm confused as to why the trailing slash > works and non-trailing slash doesn't. > > Any ideas? > > Thanks, > > - Anthony > > Hi Anthony, My guess is that it's your application server which redirects you because a "/" is missing at the end of the URL. But it redirects you on the rewritten URL. 2 options: - configure HAProxy to redirect if a / is missing (before the rewriting rule, of course) - configure HAProxy to rewirte the Location header sent by the server to insert back the /ua/ that was removed By the way, it would be safer to use the http-request rules, the configuration execution will be more predictible and readable: http-request set-path path frontend testdomain bind 172.16.0.17:80 <http://172.16.0.17/> bind 172.16.0.17:443 mode http acl redirectarchives path_beg -i /ua use_backend testbe if redirectarchives # default_backend stageweb backend testbe http-request redirect location %[path]/ code 302 unless { path_end / } http-request set-path %[path,regsub(^/ua,)] balance leastconn option forwardfor server ext1 172.17.0.18:80 <http://172.17.0.18/> check port 80 Baptiste