Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I would like to set up HAProxy to forward HTTP requests to some backend servers but I need it to also rewrite the URI part based on the Host. I've read through the doc but it seems that reqirep isn't suitable for this purpose. Any idea if this is even possible with HAProxy?

Here are the details of what I'm trying to accomplish:

Requests that come in on:

would be balanced between:


The proxy should be able to handle this for any number of domains ( can be anything, it's not limited to a fixed set of values).

For this to work HAProxy would need to rewrite a request like this:

GET /original-uri HTTP/1.1


GET /domains/ HTTP/1.1
Host: serverN

and forward that request to one of the internal servers.

share|improve this question

You can attempt to do this using the "redirect" option in HAProxy.

redirect prefix http://server1/domains/

However, it is a redirect, so it will not be transparent.

I do not believe HAProxy can rewrite URLs transparently (on their way to the backend servers).

share|improve this answer
Redirecting could probably set up to be transparent and it might work if I would be able to extract the original host name and append it to the prefix but it doesn't seem that's possible either. – DorinC Mar 19 '11 at 5:49
up vote 0 down vote accepted

Willy Tarreau, HAProxy's creator, answered my question on the HAProxy mailing list.

No, we still can't do that. We have to implement a mechanism to extract parts of requests and reuse them at other places (basically session-based variables) but there's nothing yet. It's in the roadmap though.

You'll have to find another way to do it unfortunately. If you have just a few domains, you can write a few rules (one per domain) to perform conditional rewrites (eg: if Host matches XX, rewrite URI as /domains/XX/original-uri).

If you have too many of them, you'd better look at another product for the job. I think that nginx is particularly suited at these tasks.

Regards, Willy

share|improve this answer

Your Answer


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.