You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在ManifestV3中精准重定向指定URL且不匹配嵌套页面?

解决ManifestV3中精确URL重定向的配置问题

问题出在原规则的urlFilter只是包含匹配,只要URL里包含https://stackoverflow.com就会触发重定向,所以子页面也会被错误跳转。要实现仅根域名重定向,需要用正则锚点来限定精确匹配范围:

  • ^ 匹配URL的开头
  • $ 匹配URL的结尾
  • (/)? 兼容浏览器自动给根域名添加斜杠的情况(比如访问https://stackoverflow.com时,浏览器可能自动跳转成https://stackoverflow.com/)

修改后的完整规则配置:

[
  {
    "id": 1,
    "priority": 1,
    "action": {
      "type": "redirect",
      "redirect": {
        "url": "https://stackoverflow.com/questions"
      }
    },
    "condition": {
      "urlFilter": "^https://stackoverflow.com(/)?$",
      "resourceTypes": ["main_frame"]
    }
  }
]

验证测试结果:

  • https://stackoverflow.com → 重定向(符合预期)
  • https://stackoverflow.com/ → 重定向(符合预期)
  • https://stackoverflow.com/another → 不重定向(符合预期)

内容的提问来源于stack exchange,提问作者rozsazoltan

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.15 15:12:04