Re: Question on rewriting query string
Wow, very nice, regular expressions sure are powerful :-) Here is what I ended up with: defaults mode http timeout connect 1s timeout client 1s timeout server 1s listen HTTP-in bind 127.0.0.1:80 reqrep .*(sid=[a-z0-9A-Z]*)(sid_guid=[^]*).*(strid=[0-9a-zA-Z]*) \1\2\3shopurl=search.aspx redirect code 301 prefix http://shop.companyx.com/shop.aspx? curl -i http://localhost/?sid=100026264sid_guid=342ca0f2-beb0-4132-b188-5f162941bb83; HTTP/1.1 301 Moved Permanently Content-length: 0 Location: http://shop.companyx.com/shop.aspx/?sid=100026264sid_guid=342ca0f2-beb0-4132-b188-5f162941bb83 Connection: close On May 07, 2015, at 05:27 PM, Aleksandar Lazic al-hapr...@none.at wrote: I would use reqrep https://cbonte.github.io/haproxy-dconv/configuration-1.5.html#4-reqrep Example: reqrep .*(sid=[a-z0-9A-Z]*)(sid_guid=[^]*).*(strid=[0-9a-zA-Z]*) http://shop.companyx.com/shop.aspx?\1\2\3shopurl=search.aspx I have build the regex with https://regex101.com/ Maybe there is a option to use a more generic way as in lua with. https://cbonte.github.io/haproxy-dconv/configuration-1.5.html#url_param BR Aleks
Re: Question on rewriting query string
I ended up trying out the new Lua functionality in 1.6 and was able to get this to work with it. haproxy.cfg global lua-load /path/query.lua frontend FE-HTTP bind 127.0.0.1:80 mode http http-request lua query query.lua function query(txn) local mydate = txn.sc:http_date(txn.f:date()) local sid = txn.f:url_param(sid) local sid_guid = txn.f:url_param(sid_guid) local strid = txn.f:url_param(strid) local response = response = response .. HTTP/1.1 301 Moved Permanently\n response = response .. Content-Type: text/html; charset=iso-8859-1\n response = response .. Date: .. mydate .. \n response = response .. Location: .. http://shop.companyx.com/shop.aspx?; .. sid= .. sid .. sid_guid= .. sid_guid .. strid= .. strid .. shopurl=search.aspx .. \n response = response .. Content-Length: .. buffer:len() .. \n response = response .. Connection: close\n response = response .. \n txn.res:send(response) txn:close() end I'm just curious if this is the right way to do this in HAProxy? On May 07, 2015, at 10:56 AM, Patrick Slattery patrickmslatt...@mac.com wrote: Hi, I'm trying to figure out how rewrite an incoming query string such as: http://www.example.com/?domain=companyx.comsdn=sid=123456789sid_guid=d8bfbc1a-c790-4cf8-beec-ffbbf72d9476k=mystringstrid=1e9611e961t=%20? becomes: http://shop.companyx.com/shop.aspx?sid=123456789sid_guid=d8bfbc1a-c790-4cf8-beec-ffbbf72d9476strid=1e961shopurl=search.aspx I can see how to extract each of the query params with urlp(parmname) but I don't see any obvious way of reassembling the query string from the extracted variables. Is this practical in HAProxy (any version) or should I look at using some other tool for this? Thanks.
Question on rewriting query string
Hi, I'm trying to figure out how rewrite an incoming query string such as: http://www.example.com/?domain=companyx.comsdn=sid=123456789sid_guid=d8bfbc1a-c790-4cf8-beec-ffbbf72d9476k=mystringstrid=1e9611e961t=%20? becomes: http://shop.companyx.com/shop.aspx?sid=123456789sid_guid=d8bfbc1a-c790-4cf8-beec-ffbbf72d9476strid=1e961shopurl=search.aspx I can see how to extract each of the query params with urlp(parmname) but I don't see any obvious way of reassembling the query string from the extracted variables. Is this practical in HAProxy (any version) or should I look at using some other tool for this? Thanks.