I was hoping that I could get some help with a new requirement that I’m trying to iron out. Our website is going through a redesign, and we have a ton of pages that need to be redirected to other pages due to documented links and stuff. We are already using a map file to redirect some pages, but we have a new need to redirect everything with a specific URI. For instance..
Current URI is -
/base/haproxy/safety/catfish
We need everything that has /base/haproxy/safety/ in the URI to go to /base/haproxy/new/.
This is working properly for that URI specifically (/base/haproxy/safety/), but if we go to /base/haproxy/safety/catfish, it redirects, but adds catfish to the end. So the rewriten URI looks like this /base/haproxy/new/catfish/.
Was wondering if someone could steer me towards a way I could do this, where it would literally just take the rewritten path from the map file as is without appending everything that was not rewritten to the end of the rewritten URI?
This is the config im using now.
http-request redirect location %[capture.req.uri,map(/etc/haproxy/redirects.map)] code 301 if { capture.req.uri,map(/etc/haproxy/redirects.map) -m found }
Basically I need a way to wildcard everything after /base/haproxy/safety/* to go to /base/haproxy/new/. Any help would be greatly apprecaited! Thank you!!
Another sitch is that if theres more than just one directory further, it does nothing. E.g. /base/haproxy/safety/catfish/chickenwing/. This does not get changed at all.
You should replace both map statements (in the redirect and in the if statement conditioning the redirect) with map_beg, so you are matching the beginning of the string.
This should do what you want.
I don’t see how the configuration you provided does that. Perhaps that is the behavior from a attempt with a different configuration.
However by replacing map with map_beg you should achieve the exact behavior you want.
Thank you VERY much for your assistance Lukastribus! I had tried using map_beg during my initial testing and for some reason, it wasnt working. Might have been because I was using capture.req.uri before it. (capture.req.uri,map_beg) Or maybe because I hadnt used incognito and opened a new browser between testing different commands in .cfg. I tried again just now, and it works very well! Preciate your help! I ended up finding another way as well. Please see below for anyone who is interested.
http-request redirect location %[path,map_reg(/etc/haproxy/wcredirects.map)] code 301 if { path,map_reg(/etc/haproxy/wcredirects.map) -m found }
Then in the wcredirects.map file, I added (.*) to the end of the URI I am wanting to redirect, to specify the “wildcard” part of the URI.
Tried it your way with the map_beg replacing map_reg, and that removed the necessity to use the (.*) in the .map file. Any which way, thank you VERY much for taking the time to respond! Have a great afternoon!