【问题标题】:Haproxy rewrite urlHaproxy 重写 url
【发布时间】:2016-11-04 10:06:40
【问题描述】:

我想使用 HAProxy 将传入请求 http://example.com/test/app/v1/foo/bar 路由到 http://example.com/v1/app/foo/bar

我浏览了Haproxy route and rewrite based on URI path 的示例并构建了正则表达式:

reqrep ^([^\ ]\*)\ /([a-zA-Z]\*)/([a-zA-Z]\*)/([0-9A-Za-z]\*)/(.\*)  \1\ /\4/\3/\5

但它似乎不起作用。谁能帮忙解决这个问题?

谢谢。

【问题讨论】:

  • 对此的任何帮助将不胜感激

标签: haproxy


【解决方案1】:

不要转义星号字符(如果您使用的是最新版本,您甚至可以使用引号而不转义任何内容):

reqrep ^([^\ ]*)\ /([a-zA-Z]*)/([a-zA-Z]*)/([0-9A-Za-z]*)/(.*) \1\ /\4/\3/\5

以下测试作品

$ curl -IL http://127.0.0.1/test/app/v1/foo/bar
127.0.0.1 - - [09/Jul/2016:01:45:01 +0200] "HEAD /v1/app/foo/bar HTTP/1.1" 404 0 "-" "curl/7.47.0"

【讨论】:

    猜你喜欢
    • 2015-10-27
    • 2017-11-06
    • 2015-03-29
    • 2012-12-10
    • 2012-01-02
    • 1970-01-01
    • 2018-08-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多