我無法理解如何在 HAProxy 中將重定向與 URL 重寫結合。具體來說我有這個網址
https://www.example.com/en/blog
我需要重寫為
http://blog.example.com/en
所以我需要更改主機和方案,並/blog
一步刪除路徑前綴。
答案1
我透過組合解決了這個問題reqrep
,就像redirect
這樣
use_backend website-blog if { path_reg \/?(.*)\/blog }
backend website-blog
reqrep ^([^\ :]*)\ \/?(.*)\/blog\/?(.*) \1\ /\2/\3
redirect prefix http://blog.example.com code 301