Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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.

share|improve this question

2 Answers 2

up vote 3 down vote accepted

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.

share|improve this answer

You can do this with the 'reqrep' or 'reqirep' commands:

reqrep ^([^\ ]*)\ (.*)/dev \1\ /\2 if acl_dev
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.