我有这些测试用例:
/test
/test/
/test/whatever
我想编写一个仅针对 /test/whatever
的 nginx 重写规则
我目前有
重写 ^/(test/)(.*)/some-other-page;
但这针对的是上述所有情况。
有什么想法吗?
最佳答案
^/(test/)(.*)
将匹配 /test/
因为 .*
可以匹配空字符串。
您可以使用
^/test/(.+)
.+
在 /test/
之后需要至少 1 个字符。
关于regex - 如何匹配斜杠后的所有内容以用作 nginx 重写?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53767368/