HAProxy community

Multiple backend redirections


#1

Hi
I have some problem with backend redirection

Here is my configs
frontend
acl somesite-acl path_sub /service/v2/amount/balance path_sub /service/v2/amount/fund path_sub /service/pg path_sub /service/testing
use_backend be_somesite if somesite-acl

backend be_somesite
http-request set-header Host somesite.com
reqirep ^([^\ :])\ /(.) \1\ /service/v2/amount/\2
reqirep ^([^\ :])\ /(.) \1\ /service/pg/\2
reqirep ^([^\ :]*)\ /testing \1\ /service/tested/\2
server site_node somesite.com:443 cookie S2 cookie S2 check ssl verify none

Below is what I want to achieve

example.com/service/v2/amount/balance
somesite.com/service/v2/amount/balance

example.com/service/v2/amount/fund
somesite.com/service/v2/amount/fund

example.com/service/pg
somesite.com/service/pg

example.com/service/testing
somesite.com/service/tested

Can someone try to help as I am new to haproxy and I have been working from few days to fix this, but haven’t find any solution yet


#2

try this…

 http-response redirect code 301 location somesite.com%[customHeader] unless { hdr_beg(host) -i example.com }

I got it from the example in the docs from this section - https://cbonte.github.io/haproxy-dconv/1.8/configuration.html#4.2-redirect%20scheme

Since %[capture.req.uri] would not be available in backend, you have to store that value in a custom request header & read that value in backend section