On Mon, Jul 2, 2012 at 10:27 PM, Dave <[email protected]> wrote:
> Hello,
>  I have a question about rewriting URLs with HAProxy. I'm aware this
> isn't the correct place to do it, but due to a long story essentially
> it has to be. What I would like to do is rewrite URLs going to the
> webserver like this --
>
> www.test.com/xyz/ -> xyz.test.com/xyz/
>
> This is complicated (as far as I can tell) for a few reasons. Firstly,
> I need to pickup the "xyz", then secondly I need to rewrite the domain
> with it even though it's part of the path. The problem is that I can't
> use (again afaik) something like reqrep because by replacing Host: I
> can easily change www to xyz but I cannot pickup xyz as it's not in
> the Host header (it's part of the url).
>
> Basically I need to match the path, and use that to replace www in the host..
>
> Any ideas?
>
> Thank you
> Dave
>

Hi,

HAProxy can only replace strings in one line at a time.
As you mentioned it in your mail, the URL line and the Host header
line are two separated lines, so you can't pick up information from
one of them to rename the other one.

There are some VERY VERY dirty tricks that you could try, but it will
work ONLY if the domain name never change.
You can first delete the Host header, then, when rewriting the URL
just append to the end of the rewrite a "\r\nHost: \X.test.com\r\n"
where X stands for the number of the substring in your regexp.
That way, in a single line, you can change both host header and URL.
The problem is that the domain name must be hardcoded.

Again, bear in mind this is not the cleanest way to do it.

cheers


Reply via email to