如何在 Caddyfile 中重定向并保留路径的某些部分?

问题描述 投票:0回答:1

我想像这样重定向 URL

/origin/something
到此
/destination/something
。 我尝试使用
redir
来完成此操作,但我无法通过使用占位符来获取路径的某些部分。 然后我尝试用这些方式重写:

rewrite /origin {
  r (.*)
  to /destination{1}
}

rewrite {
  if {path} not_starts_with /origin
  to /{path} /{path}/
}
rewrite {
  r ^/origin/(.*)
  to /destination{1}
}

rewrite {
  if {path} not_starts_with /origin
  to /{path} /{path}/
}

这两种方式都行不通。我究竟做错了什么?我该如何进行此重定向?

caddy caddyfile
1个回答
0
投票

您可以将

path_regexp
rewrite
一起使用:

@path path_regexp path ^\/origin\/(.*)$
rewrite @path /destination/{re.path.1}
© www.soinside.com 2019 - 2024. All rights reserved.