我想像这样重定向 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}/
}
这两种方式都行不通。我究竟做错了什么?我该如何进行此重定向?
您可以将
path_regexp
与 rewrite
一起使用:
@path path_regexp path ^\/origin\/(.*)$
rewrite @path /destination/{re.path.1}