Using haproxy version 1.4.24 on Ubuntu 14.04

I would like to use haproxy to rewrite and redirect urls which are no longer valid to their new equivalent. I am already using haproxy as the reverse proxy and load balancer. I have the rewrite working correctly but when I try to redirect I either end up with no redirect or in a redirect loop. I read on a few places that a technique for this is to rewrite and redirect the url using prefix in the frontend but I'm not having any luck. Any help would be appreciated. Thanks.

    log local0
    log local1 notice
    maxconn 4096
    user haproxy
    group haproxy
    spread-checks 0

    log global
    mode http
    option httplog
    option dontlognull
    retries 3
    timeout queue 20000
    timeout client 50000
    timeout connect 5000
    timeout server 50000

frontend haproxy-0-80
    default_backend haproxy_service
    acl old_url path_beg -i /post
    # The below doesn't appear to have any effect
    reqrep ^([^\ :]*)\ /post/\d+/(.+)/?     \1\ /\2
    redirect prefix code 301 if old_url

backend haproxy_service
    balance leastconn
    cookie SRVNAME insert
    # The below properly handles the rewrite
    reqrep ^([^\ :]*)\ /post/\d+/(.+)/?     \1\ /\2
    server ghost-0-2368 maxconn 100 cookie S0 check
  • I could upgrade to the 1.15.x version if this isn't possible in 1.14.x
    – hatch
    Dec 13, 2014 at 23:39

1 Answer 1


As it turns out I was very close to a working config.

Changing the redirect line to read redirect prefix / code 301 if old_url made it work as expected.

I wrote a blog post which outlines the problem in a little more detail: https://fromanegg.com/post/2014/12/05/how-to-rewrite-and-redirect-with-haproxy/

  • Doesn't seem to work for me as the acl condition is being checked after the request has been regex replaced, meaning the old_url condition will fails if the check is executed after reqrep.
    – Mike
    Apr 12, 2019 at 2:04

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .