0

I'm currently trying to rewrite url based on extensions and subdomains, but my update doesn't work, so I will try to explain my procedure:

I would like to rewrite this kind of url

https://mydomain.tld/image.jpg

to

https://jpg.mydomain.tld/image

so I update my haproxy.cfg and add to my frontend these rules:

frontend web
    bind *:80
    acl p_ext_jpg path_end -i .jpg
    acl p_ext_png path_end -i .png
    acl mydomain hdr(host) -i mydomain.tld
    reqrep ^([^\ :]*)\ /(*).(jpg|png)     \1\ /\2
    use_backend backend_static if  p_ext_jpg p_ext_png mydomain
    default_backend backend_web

My current nginx rule who work:

rewrite "^/([0-9]+).(jpg|png)$" $scheme://$2.mydomain.tld/$1;

My current problems:

  1. I don't know how to replace mydomain by (jpg|png).mydomain
  2. any reqrep seems not be used by my haproxy

I only want to rewrite url and forward to my backend not redirection.

Thanks for your help and sorry for my english.

1
  • I don't have a full answer, but you're going to need to use some combination of http-request directives because you're making changes to more than just a single header here (as your reqrep is doing). You'll probably need to use http-request with set-uri, set-path, set-uri, set-header, or replace-header.
    – GregL
    Feb 7, 2017 at 12:56

1 Answer 1

0

Your backend is never used because your "if" is an implicit AND. Use an "or":

use_backend backend_static if mydomain { p_ext_jpg or p_ext_png }

And so you can rewrite the host:

reqirep ^Host:\ mydomain.tld Host:\ jpg.mydomain.tld if mydomain p_ext_jpg
reqirep ^Host:\ mydomain.tld Host:\ png.mydomain.tld if mydomain p_ext_png

"http-request" is a "newer" way to solve this...

4

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .