I'm having trouble understanding how to combine a redirect with an URL rewrite in HAProxy. Specifically I have this URL


that I need to rewrite to


So I need to change the host and scheme, and remove the /blog path prefix in one step.


I solved it by combining reqrep and redirect like so

use_backend website-blog if { path_reg \/?(.*)\/blog }

backend website-blog
  reqrep        ^([^\ :]*)\ \/?(.*)\/blog\/?(.*)    \1\ /\2/\3
  redirect      prefix http://blog.example.com    code 301

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.