首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >防火墙托管路由ReWrites (异常路径)

防火墙托管路由ReWrites (异常路径)
EN

Stack Overflow用户
提问于 2022-09-12 14:58:23
回答 1查看 23关注 0票数 0

我正在尝试创建一个防火墙路由规则,它将将特定子目录下的任何请求重新路由到服务器上的一个特定文件。

如果我有一个正常的文件路径(带有一个扩展名),这是可行的,但是如果我已经从最初的请求中删除了这个扩展,它就不起作用了。

有没有人知道这种“重写”逻辑是如何工作的,有没有一种利用这种方式的方法?

(或者我只是做错了,因为我不清楚为什么第一条规则也不起作用)

使用此规则集:

代码语言:javascript
复制
    "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"
      }
    ]

测试结果:

代码语言:javascript
复制
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
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-09-12 16:15:59

对于第一个问题,由于重定向比重写具有更高的优先级,所以在到达重写引擎时,.html可能已经从传入的URL中删除了。

代码语言:javascript
复制
{
  "source": "/access-token/somefolder/else",
  "destination": "/access-token/2.json"
}

对于下面的项目,不要转义\字符,您也不需要锚。

代码语言:javascript
复制
{
  "regex": "/access-token/\d+",
  "destination": "/access-token/2.json"
}
代码语言:javascript
复制
{
  "regex": "/access-token/\d+\.json",
  "destination": "/access-token/1.json"
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73691268

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档