Welcome! Log In Create A New Profile

Advanced

Rewrite image path based on HTTP_REQUEST

Posted by Lotic Lists 
Lotic Lists
Rewrite image path based on HTTP_REQUEST
May 17, 2018 04:00PM
Hi experts



How can I rewrite a image path based on URL?



Example, users request the url www.example.com/images/logo.png, haproxy just
balance to backend servers normally.

Now users request www.newdomain.com, I need rewrite URI to
/images/new-logo.png



Tks.

Marcelo
Aleksandar Lazic
Re: Rewrite image path based on HTTP_REQUEST
May 19, 2018 03:50AM
On 17/05/2018, Lotic Lists wrote:
> Hi experts
>
> How can I rewrite a image path based on URL?
>
> Example, users request the url www.example.com/images/logo.png, haproxy just
> balance to backend servers normally.
>
> Now users request www.newdomain.com, I need rewrite URI to
> /images/new-logo.png

Well what have you already tried?

I would try, untested.

https://cbonte.github.io/haproxy-dconv/1.8/configuration.html#4.2-reqrep

acl old_dom hdr(host) -i www.example.com
acl old_path path_beg -i /images/logo.png

reqrep "^([^ :]*) /images/logo.png /images/new-logo.png" if old_dom && old_path
reqirep "^Host: www.example.com "Host: www.newdomain.com" if old_dom && old_path

> Tks.
>
> Marcelo

Regards
Aleks
Jarno Huuskonen
Re: Rewrite image path based on HTTP_REQUEST
May 23, 2018 07:50PM
Hi,

On Sat, May 19, Aleksandar Lazic wrote:
> On 17/05/2018, Lotic Lists wrote:
> > How can I rewrite a image path based on URL?
> >
> > Example, users request the url www.example.com/images/logo.png, haproxy just
> > balance to backend servers normally.
> >
> > Now users request www.newdomain.com, I need rewrite URI to
> > /images/new-logo.png
>
> Well what have you already tried?
>
> I would try, untested.
>
> https://cbonte.github.io/haproxy-dconv/1.8/configuration.html#4.2-reqrep
>
> acl old_dom hdr(host) -i www.example.com
> acl old_path path_beg -i /images/logo.png
>
> reqrep "^([^ :]*) /images/logo.png /images/new-logo.png" if old_dom && old_path
> reqirep "^Host: www.example.com "Host: www.newdomain.com" if old_dom && old_path

If you just need to change the path then http-request set-path should be
enough(https://cbonte.github.io/haproxy-dconv/1.8/configuration.html#4-http-request).

Something like:
acl new_dom hdr_dom(host) -i www.newdomain.com
acl old_path path_beg -i /images/logo.png
http-request set-path "/images/new-logo.png" if new_dom old_path

-Jarno

--
Jarno Huuskonen - System Administrator | jarno.huuskonen atsign uef.fi
Sorry, only registered users may post in this forum.

Click here to login