Search code examples
regexhaproxy

HAProxy replace URL


i have domain with URL:

https://example.com/browse/TEST-1

i need in ha-proxy 2.0 change this URL to:

https://example.com/issue/TEST-1

i try:

http-request replace-path ^([^\ :]*)\ /browse/(.*) \1\ /issue/\2
http-request replace-path ^([^\ :]*)\ /browse/(.*)     \1\ /issue/\2
reqrep ^([^\ :]*)\ /browse/(.*)     \1\ /issue/\2
http-request replace-uri /browse/(.*) /issue/\1
http-request replace-path ^/browse/(.*) /issue/\1

I'm out of ideas, what am I doing wrong?


Solution

  • No need to mess up with regex for this. I believe adding this on the haproxy.cfg file will do the job:

    frontend http_front
       bind *:80
       bind *:443 ssl crt /path/to/ssl/certificate.pem
    
       acl is_test1 path_beg /browse/TEST-1
    
       http-request set-path /issue/TEST-1 if is_test1