Welcome! Log In Create A New Profile

Advanced

URL rewrite question

Posted by Sriram Chavali 
Sriram Chavali
URL rewrite question
February 04, 2010 09:20PM
I am trying to rewrite URLs using haproxy's reqirep directive. The url that I am trying to rewrite is of the pattern
/action/register?param1=foo&param2=bar&param3=baz

The URL that I want to be rewritten is
/newaction?param1=foo&param2=bar&param3=baz on the condition that whenever param2=bar

The ordering of the query string parameters can be random, i.e param2 could be the 1st parameter or the last one.

Can somebody please help me?

Thanks
Sriram
Holger Just
Re: URL rewrite question
February 04, 2010 10:40PM
On 2010-02-04 21:15, Sriram Chavali wrote:
> I am trying to rewrite URLs using haproxy's reqirep directive. The url that I am trying to rewrite is of the pattern
> /action/register?param1=foo&param2=bar&param3=baz
>
> The URL that I want to be rewritten is
> /newaction?param1=foo&param2=bar&param3=baz on the condition that whenever param2=bar
>
> The ordering of the query string parameters can be random, i.e param2 could be the 1st parameter or the last one.

In Haproxy 1.3.x it is currently not possible to issue a reqirep on a
conditional basis. This is however introduced in Haproxy 1.4-rc1. There
you could solve your problem using something like this:

acl baz url_sub &param2=bar ?param2=bar
reqirep ([^\ ]*)\ /action/register\?(.*) \1\ /newaction\?\2 if baz

On 1.3.x you could however use something like the following which
performs a content switch based on the acl and performs the reqirep
later in the backend. You might want to look into the track keyword for
the servers.

frontend foo
bind :80
mode http

acl baz url_sub &param2=bar ?param2=bar
use_backend baz if baz

backend baz
reqirep ([^\ ]*)\ /action/register\?(.*) \1\ /newaction\?\2
server foo 192.168.1.1:80

Yes, this is uggly but as far as I know it is the only possibility by
now. (And yes, I see forward to remove many such backends in my
installations too)

--Holger
Willy Tarreau
Re: URL rewrite question
February 06, 2010 11:00AM
Hi,

On Thu, Feb 04, 2010 at 10:31:03PM +0100, Holger Just wrote:
> On 2010-02-04 21:15, Sriram Chavali wrote:
> > I am trying to rewrite URLs using haproxy's reqirep directive. The url that I am trying to rewrite is of the pattern
> > /action/register?param1=foo&param2=bar&param3=baz
> >
> > The URL that I want to be rewritten is
> > /newaction?param1=foo&param2=bar&param3=baz on the condition that whenever param2=bar
> >
> > The ordering of the query string parameters can be random, i.e param2 could be the 1st parameter or the last one.
>
> In Haproxy 1.3.x it is currently not possible to issue a reqirep on a
> conditional basis. This is however introduced in Haproxy 1.4-rc1. There
> you could solve your problem using something like this:
>
> acl baz url_sub &param2=bar ?param2=bar
> reqirep ([^\ ]*)\ /action/register\?(.*) \1\ /newaction\?\2 if baz

Well, since both entries are on the same line and param2 is
always after the string to match, you can still write it
without ACLs in 1.3 :

reqrep ([^\ ]*)\ /action.register\?([^&]*&)*param2=bar(.*) \1\ /newaction\?\2param2=bar\3

That way the regex will only match when "param2=bar" appears in one of
the parameters.

Willy
Holger Just
Re: URL rewrite question
February 06, 2010 01:10PM
On 2010-02-06 10:55, Willy Tarreau wrote:
> reqrep ([^\ ]*)\ /action.register\?([^&]*&)*param2=bar(.*) \1\ /newaction\?\2param2=bar\3

This does it. Looks like your Regex Kung Fu is stronger than mine. But
well, it was late :)

--Holger
Sorry, only registered users may post in this forum.

Click here to login