Is it possible to remove part of a path in HAProxy in a redirect

haproxy

I'm using HAProxy to set a cookie when you visit mydomain.com/dev and redirects to mydomain.com .

The purpose of this is to offer a way to visit a development version of the site instead of the production site, while keeping everything else the same.

The pertinent config line looks something like this:

frontend webfarm 1.2.3.4:80
    acl acl_dev path_end /dev

    redirect location / code 302 set-cookie SERVERID=live03 if acl_dev

    default_backend default_farm

Now, instead of redirecting to the root domain, I'd just like to strip off the /dev path. So if I went to mydomain.com/foo/dev it would set the cookie and redirect to mydomain.com/foo

Is this possible with HAProxy, or would I need to use mod_rewrite in the apache backend server?

Note: I don't need a mod_rewrite rule, just looking for whether this is possible in HAproxy.

Best Answer

You can do URL rewriting and HTTP headers manipulation (add, modify, and remove headers).

However, the haproxy documentation states that this is not encouraged and your setup should work (without reconfiguration) with and without haproxy running between your clients and your real servers. Following this recommendation, it will be better to use apache mod_rewrite.