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

Chrome扩展:使用regexSubstitution重定向时保留路径异常问题

解决Chrome扩展重定向Amazon URL的问题

你的问题出在正则替换的捕获组引用写法错误,导致$1被当成字面量进行URL编码,最终出现%241的错误。

修正方案

修改rule.json中的regexSubstitution部分,将$1替换为\\1(JSON中需要转义反斜杠,实际传递给Chrome的是\1,这是declarativeNetRequest识别的捕获组引用格式)。

修正后的rule.json

[
   {
      "id":1,
      "priority":1,
      "action":{
         "type":"redirect",
         "redirect":{
            "regexSubstitution":"https://www.amazon.de\\1"
         }
      },
      "condition":{
         "regexFilter":"^https://www\\.amazon\\.com(/.*)?$",
         "resourceTypes":[
            "main_frame"
         ]
      }
   }
]

额外优化(可选)

如果需要支持不带www的amazon.com域名,可修改regexFilter和替换字符串,让所有子域名的请求都重定向到带www的amazon.de:

{
   "condition":{
      "regexFilter":"^https://(www\\.)?amazon\\.com(/.*)?$",
      "resourceTypes":["main_frame"]
   },
   "action":{
      "type":"redirect",
      "redirect":{
         "regexSubstitution":"https://www.amazon.de\\2"
      }
   }
}

验证步骤

  1. 保存修改后的rule.json
  2. 在Chrome扩展管理页面重新加载你的扩展
  3. 访问https://www.amazon.com或带路径的https://www.amazon.com/dp/XXXX,检查是否正确重定向到对应的amazon.de地址

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.28 00:13:29