Note, the TLD and domain can also change and must be part of the regex.
'static' is the only string which will not change. In all cases where it is
the subdomain we want it to be removed and replaced by the first element of
the path. That element should also be removed from the path.


static.domainA.tldW/site1/resource1.jpg => site1.domainW.tldA/resource1.jpg
static.domainB.tldX/site2/resource2.js => site2.domainB.tldX/resource2.js
static.domainC.tldY/site3/resource3.gif => site3.domainC.tldY/resource3.gif
static.domainD.tldZ/site4/someDir/resource4.txt
=> site4.domainD.tldZ/someDir/resource4.txt

I'm thinking it an be done with http-request (set-var, set-path,
replace-header, etc)
LUA could also be an option.

On Thu, Jun 9, 2016 at 2:13 PM, Chaim Keren-Tzion <ch...@intercomp.co.il>
wrote:

> Hi,
>
> Thanks.
>
> # haproxy -vv
> HA-Proxy version 1.6.4 2016/03/13
> Copyright 2000-2016 Willy Tarreau <wi...@haproxy.org>
>
> Build options :
>   TARGET  = linux2628
>   CPU     = generic
>   CC      = gcc
>   CFLAGS  = -m64 -march=x86-64 -O2 -g -fno-strict-aliasing
> -Wdeclaration-after-statement
>   OPTIONS = USE_ZLIB=1 USE_OPENSSL=1 USE_LUA=1 USE_PCRE=1
>
> Default settings :
>   maxconn = 2000, bufsize = 16384, maxrewrite = 1024, maxpollevents = 200
>
> Encrypted password support via crypt(3): yes
> Built with zlib version : 1.2.7
> Compression algorithms supported : identity("identity"),
> deflate("deflate"), raw-deflate("deflate"), gzip("gzip")
> Built with OpenSSL version : OpenSSL 1.0.1e-fips 11 Feb 2013
> Running on OpenSSL version : OpenSSL 1.0.1e-fips 11 Feb 2013
> OpenSSL library supports TLS extensions : yes
> OpenSSL library supports SNI : yes
> OpenSSL library supports prefer-server-ciphers : yes
> Built with PCRE version : 8.32 2012-11-30
> PCRE library supports JIT : no (USE_PCRE_JIT not set)
> Built with Lua version : Lua 5.3.2
> Built with transparent proxy support using: IP_TRANSPARENT
> IPV6_TRANSPARENT IP_FREEBIND
>
> Available polling systems :
>       epoll : pref=300,  test result OK
>        poll : pref=200,  test result OK
>      select : pref=150,  test result OK
> Total: 3 (3 usable), will use epoll.
> --------------------------------------------
>
> We tried this but it has not worked at all:
>   acl host_static hdr_beg(host) -i static.
>   reqirep ^([^\ :]*\ \/)([^\/]+)(\/.*\n)Host:\ static\.([^\/]+?)$
> \1\2\3Host:\ \2.\4 if host_static
>   reqirep ^([^\ :]*)\ /[^/]+/(.*)     \1\ /\2 if host_static
>
>
>
> On Thu, Jun 9, 2016 at 12:51 PM, Aleksandar Lazic <al-hapr...@none.at>
> wrote:
>
>> Hi.
>>
>> Am 09-06-2016 11:18, schrieb Chaim Keren-Tzion:
>>
>> Hi,
>>>
>>> Is there a way to rewrite the Host based on Path?
>>>
>>> I'm trying to redirect all requests of type:
>>>
>>> static.domain.com/site1/resource.jpg
>>> static.domain.com/site1/resource2.js
>>> static.domain.com/site2/resource3.gif
>>> static.domain.com/site2/someDir/resource4.txt
>>>
>>> to
>>>
>>> site1.domain.com/resource.jpg
>>> site1.domain.com/resource2.js
>>> site2.domain.com/resource3.gif
>>> site2.domain.com/someDir/resource4.txt
>>>
>>> Basically, if the host is static.domain.com:
>>>
>>> * New subdomain is based on the first part of the original path, with
>>> the same TLD.
>>> * New path is the original path not including the first part.
>>>
>>
>> Please can you send the haproxy -vv
>>
>> What have you already done to solve the requirement?
>> Please can you send the relevant part from the config.
>>
>> Maybe the doc could help you to find a good start point.
>>
>>
>> http://cbonte.github.io/haproxy-dconv/configuration-1.5.html#4.2-http-request
>> http://cbonte.github.io/haproxy-dconv/configuration-1.5.html#redirect
>> http://cbonte.github.io/haproxy-dconv/configuration-1.5.html#4.2-reqrep
>>
>> regex build with https://regex101.com/
>>
>> Testdata:
>> GET static.domain.com/site1/resource.jpg HTTP/1.1
>> GET static.domain.com/site2/someDir/resource4.txt HTTP/1.1
>>
>> reqrep ^([^\ :]*)\ .*?/(\w+)/(.*)\     \1.domain.com/\2
>> <http://1.domain.com/%5C2>
>>
>> Hth Aleks
>>
>
>
>
> --
> *Chaim Keren-Tzion*
> ch...@intercomp.co.il
> +972-54-465-2983
>



-- 
*Chaim Keren-Tzion*
ch...@intercomp.co.il
+972-54-465-2983

Reply via email to