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:
- I don't know how to replace mydomain by (jpg|png).mydomain
- 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.
Best Answer
Your backend is never used because your "if" is an implicit AND. Use an "or":
And so you can rewrite the host:
"http-request" is a "newer" way to solve this...