Quantcast
Channel: HAProxy community - Latest topics
Viewing all articles
Browse latest Browse all 4849

Replace path clarification

$
0
0

I’m attempting to create some sort of virtual directory that exists at any level, even if nonexistent path or the domain name itself. I need to keep the last two segments of the path, one known, one unknown, get rid of the rest, pick the backend and I’m done. I’ve already found the right keyword (http-request replace-path) but it’s not clear if it will replace only that matched regex, or the whole string. That’s why I’m here. :nerd_face:

For instance, I need something like:

IF REQUEST IS                                                                  REWRITE AS
<sch><dom1>:<prt>/wiki/statcap/404.svg         → http://resourceserver:80/statcap/404.svg
<sch><dom1>:<prt>/statcap/404.svg              → http://resourceserver:80/statcap/404.svg
<sch><dom2>:<prt>/callme/mrs/statcap/404.svg   → http://resourceserver:80/statcap/404.svg

So I came up with <1> if everything is replaced regardless of how much is matched, with <2a> or <2b> if only what’s matched gets replaced and I was going to use <3> to filter it down as advised (it’s not taken into consideration for the match, right?)

 1. '  http-request replace-path (\/statcap\/)(.*)$ \1\2        '
2a. '  http-request replace-path (\/.+)(\/statcap\/)(.*)$ \2\3  '
2b. '  http-request replace-path \/.+(\/statcap\/)(.*)$ \1\2    '
 3. '  { var(txn.txnpath) -m dir -i statcap }                   '

Would it work? Am I even close?

Also, could you clarify if "/"s need to be escaped? In the docu they aren’t. But then again “\” not “$” is used for backreferences. Also not mentioned is case matching, with regsub you’d use commas in I think it was parenthesis or sq brackets, something like regsub(<regex>,<replace>,ig), I think. But here I didn’t get anything of that, it’s a little misplaced, it builds on http-request replace-header which itself only mentions it’s case-sensitive and that’s it.

1 post - 1 participant

Read full topic


Viewing all articles
Browse latest Browse all 4849

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>