Reg Exp for URL in HAProxy

21,137

You need to construct two regex's that are mutually exclusive: only one can be true at a time:

How about if you make the second item be a regex like:

^/path[^/]

The [^/] means "any character that is not /".

Here are three URLs that are mutually exclusive:

acl fb1 path_reg ^/path$          # Just /path
acl fb2 path_reg ^/path/$         # Just /path/
acl fb3 path_reg ^/path/..*$      # /path/ plus at least 1 character
Share:
21,137

Related videos on Youtube

Nimjox
Author by

Nimjox

Updated on September 18, 2022

Comments

  • Nimjox
    Nimjox over 1 year

    I'm trying to build a reg exp for haproxy that will match the second URL and direct it to a different acl than the first:

    mysite.com/path/
    mysite.com/path/something_random
    

    The issue is that my first reg exp matches both urls above when it should only match the second one. I can't find more documentation on haproxy regex's format either so I'm not even sure where to reference the reg exp format I should be using for matching. Can reg exp pro's help me I'm new to this thanks.

     acl filebrowser_route path_reg ^/path/.*
     acl filebrowser url_beg /path
    
    • GregL
      GregL over 8 years
      It looks to me like both your ACLs will match both URLs. If the first URL is ONLY ever going to be mysite.com/path/, then the ACL should be acl filebrowser path /path/
  • Nimjox
    Nimjox over 8 years
    Really great clear examples on the regex. Thanks this works.
  • thenewasker
    thenewasker almost 6 years
    I just see the answer from TomOnTime and follow it. I think the correct regex for "any character that is not /" should be: ^/path[^/] ^ but not ~