首页 > 解决方案 > 如何在 Caddyfile 中重定向保留路径的某些部分?

问题描述

我想将这样的 URL 重定向 /origin/something到 this /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}/
}

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

标签: caddycaddyfile

解决方案


推荐阅读