我正在尝试使用 Ninx 重定向 URL,但我很难做到正确:
example.com/{dynamic1}/foo/bar/{dynamic2}
到example.com/{dynamic1}/bar/{dynamic2}
基本上我正在尝试删除/foo/
URL 的一部分。
我尝试过以下方法:
location ~* ^/(.*)/foo/bar/(.*)$ {
return 302 ^/$1/bar/$2?$args;
}
并且:
location ~ ^/([^/]*)/foo/bar/(.*)$ {
return 302 ^/$1/bar/$2?$args;
}
但这会引发错误414 Request-URI Too Large
,并且 URL 最终变成(为清楚起见已缩短):
dynamic1/cams/bar/%5E/dynamic1/bar/%5E/dynamic1/bar/%5E/dynamic1/bar/%5E/dynamic1/bar/%5E/dynamic1/bar/%5E/dynamic1/bar/%5E/dynamic1/bar/%5E/dynamic1/bar/%5E/dynamic1/bar/%5E/dynamic1/bar/%5E/dynamic1/bar/%5E/dynamic1/bar/%5E/dynamic1/bar/%5E/dynamic1/bar/%5E/dynamic1/bar/%5E/dynamic1/bar/%5E/dynamic1/bar/%5E/dynamic1/bar/%5E/dynamic1/bar/%5E/dynamic1/bar/%5E/dynamic1/bar/%5E/dynamic1/bar/%5E/dynamic1/bar/%5E/dynamic1/bar/%5E/dynamic1/bar/%5E/dynamic1/bar/%5E/dynamic1/bar/%5E/dynamic1/bar/%5E/dynamic1/bar/%5E/dynamic1/bar/%5E/dynamic1/bar/%5E/dynamic1/bar/%5E/dynamic1/bar/%5E/dynamic1/bar/%5E/dynamic1/bar/%5E/dynamic1/bar/%5E/dynamic1/bar/%5E/dynamic1/bar/%5E/dynamic1/bar/%5E/dynamic1/bar/%5E/dynamic1/bar/%5E/dynamic1/bar/%5E/dynamic1/bar/%5E/dynamic1/bar/%5E/dynamic1/%5E/dynamic1/bar/%5E/dynamic1/bar/%5E/dynamic1/bar/%5E/dynamic1/bar/%5E/dynamic1/bar/%5E/dynamic1/bar/%5E/dynamic1/bar/%5E/dynamic1/bar/%5E/dynamic1/bar/%5E/dynamic1/bar/%5E/dynamic1/bar/%5E/dynamic1/bar/%5E/dynamic1/bar/%5E/dynamic1/bar/%5E/dynamic1/bar/dynamic2?
我究竟做错了什么?
请注意,一旦我正确理解,我将用 301 替换 302。
答案1
您在目标 URL 路径的开头放置了一个插入符号,而您似乎打算将其重定向到该路径。这不属于那里,因此会%5E
反复出现。