HAProxy替换URL

huangapple go评论58阅读模式
英文:

HAProxy replace URL

问题

我有一个带有URL的域名:

https://example.com/browse/TEST-1

我需要在ha-proxy 2.0中将此URL更改为:

https://example.com/issue/TEST-1

我尝试了以下方式:

http-request replace-path ^([^\ :])\ /browse/(.) \1\ /issue/\2
http-request replace-path ^([^\ :])\ /browse/(.) \1\ /issue/\2
reqrep ^([^\ :])\ /browse/(.) \1\ /issue/\2
http-request replace-uri /browse/(.) /issue/\1
http-request replace-path ^/browse/(.
) /issue/\1

我想不出来了,我做错了什么?

英文:

i have domain with URL:

https://example.com/browse/TEST-1

i need in ha-proxy 2.0 change this URL to:

https://example.com/issue/TEST-1

i try:

http-request replace-path ^([^\ :]*)\ /browse/(.*) \ /issue/
http-request replace-path ^([^\ :]*)\ /browse/(.*)     \ /issue/
reqrep ^([^\ :]*)\ /browse/(.*)     \ /issue/
http-request replace-uri /browse/(.*) /issue/
http-request replace-path ^/browse/(.*) /issue/

I'm out of ideas, what am I doing wrong?

答案1

得分: 0

不需要使用正则表达式处理这个。我相信在haproxy.cfg文件中添加以下内容就可以完成任务:

frontend http_front
   bind *:80
   bind *:443 ssl crt /path/to/ssl/certificate.pem

   acl is_test1 path_beg /browse/TEST-1

   http-request set-path /issue/TEST-1 if is_test1
英文:

No need to mess up with regex for this. I believe adding this on the haproxy.cfg file will do the job:

frontend http_front
   bind *:80
   bind *:443 ssl crt /path/to/ssl/certificate.pem

   acl is_test1 path_beg /browse/TEST-1

   http-request set-path /issue/TEST-1 if is_test1

答案2

得分: -1

这是一个参考。

这个模式将捕获元素,除了""/browse/""。

(.+?\/\/.+)\/.+\/(.+)

而且,您可以替换为,

/issue/
英文:

Here is a reference.

This pattern will capture the elements, except for "/browse/".

(.+?\/\/.+)\/.+\/(.+)

And, you can replace with,

/issue/

huangapple
  • 本文由 发表于 2023年6月19日 21:36:56
  • 转载请务必保留本文链接:https://go.coder-hub.com/76507182.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定