{
  "id": "nextjs/rewrite-query-params-lost",
  "signature": "Error: Rewrite query parameters are lost after redirect in middleware",
  "signature_zh": "错误：中间件重写后查询参数丢失",
  "regex": "Rewrite query parameters are lost after redirect in middleware",
  "domain": "nextjs",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "When using NextResponse.rewrite() in middleware with a URL that includes query parameters, the parameters are stripped if the destination URL already has its own query string or if the rewrite target is a static path.",
  "root_cause_type": "generic",
  "root_cause_zh": "在中间件中使用 NextResponse.rewrite() 时，如果目标 URL 已有自己的查询字符串或目标是静态路径，则查询参数会被剥离。",
  "versions": [
    {
      "version": "next@14.1.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "next@14.2.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "next@15.0.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "Next.js normalizes the URL and may strip duplicate or malformed query strings, especially if the destination path is a file-based route.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Redirect changes the URL in the browser, which may break client-side state or cause infinite loops if the redirect target is the same page.",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "The request object is immutable in middleware; modifying it directly has no effect on the rewrite.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Use NextResponse.next() with a modified URL that includes query parameters, then handle the rewrite in the page component using the searchParams prop.",
      "success_rate": 0.85,
      "how": "Use NextResponse.next() with a modified URL that includes query parameters, then handle the rewrite in the page component using the searchParams prop.",
      "condition": "",
      "sources": []
    },
    {
      "action": "Store the query parameters in a cookie or header before rewriting, then read them in the page component.",
      "success_rate": 0.75,
      "how": "Store the query parameters in a cookie or header before rewriting, then read them in the page component.",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "使用 NextResponse.next() 并修改 URL 包含查询参数，然后在页面组件中通过 searchParams 属性处理重写。",
    "在重写前将查询参数存储在 cookie 或 header 中，然后在页面组件中读取。"
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://nextjs.org/docs/app/api-reference/functions/next-response#rewrite",
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.85,
  "fix_success_rate": 0.85,
  "resolvable": "true",
  "first_seen": "2024-03-15",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}