我正在尝试创建一个防火墙路由规则,它将将特定子目录下的任何请求重新路由到服务器上的一个特定文件。
如果我有一个正常的文件路径(带有一个扩展名),这是可行的,但是如果我已经从最初的请求中删除了这个扩展,它就不起作用了。
有没有人知道这种“重写”逻辑是如何工作的,有没有一种利用这种方式的方法?
(或者我只是做错了,因为我不清楚为什么第一条规则也不起作用)
使用此规则集:
"rewrites": [
{
"source": "/access-token/somefolder/else.html",
"destination": "/access-token/2.json"
},
{
"regex": "^/access-token/[\\d]+$",
"destination": "/access-token/2.json"
},
{
"regex": "^/access-token/[\\d]+\\.json$",
"destination": "/access-token/1.json"
},
{
"source": "**",
"destination": "/index.html"
}
]测试结果:
request : https://[root]//access-token/somefolder/else.html <-- this path does not exist, i was only using this as a test
expected: routes to 'destination'
actual : routes to root (probably hitting final rule?)
request : https://[root]/access-token/12
expected: routes to 'destination'
actual : routes to "404 not found"
request : https://[root]/access-token/12.json
expected: routes to 'destination'
actual : re-routes as intended发布于 2022-09-12 16:15:59
对于第一个问题,由于重定向比重写具有更高的优先级,所以在到达重写引擎时,.html可能已经从传入的URL中删除了。
{
"source": "/access-token/somefolder/else",
"destination": "/access-token/2.json"
}对于下面的项目,不要转义\字符,您也不需要锚。
{
"regex": "/access-token/\d+",
"destination": "/access-token/2.json"
}{
"regex": "/access-token/\d+\.json",
"destination": "/access-token/1.json"
}https://stackoverflow.com/questions/73691268
复制相似问题