{
  "id": "nextjs/middleware-rewrite-absolute-url",
  "signature": "Error: URL is not valid. Middleware rewrite target must be a relative path or internal URL.",
  "signature_zh": "错误：URL 无效。中间件重写目标必须是相对路径或内部 URL。",
  "regex": "Error: URL is not valid\\. Middleware rewrite target must be a relative path or internal URL\\.",
  "domain": "nextjs",
  "category": "config_error",
  "subcategory": null,
  "root_cause": "Middleware uses NextResponse.rewrite() with an absolute external URL instead of a relative path or internal route. Next.js middleware rewrites are restricted to same-origin paths.",
  "root_cause_type": "generic",
  "root_cause_zh": "中间件使用 NextResponse.rewrite() 时传入了绝对外部 URL，而非相对路径或内部路由。Next.js 中间件重写仅限于同源路径。",
  "versions": [
    {
      "version": "14.2.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "15.0.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "14.2.15",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "Adding trailing slash or encoding the URL",
      "why_fails": "The issue is the domain mismatch, not URL formatting. Trailing slashes or encoding don't change the absolute external nature.",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    },
    {
      "action": "Using NextResponse.redirect() instead of rewrite()",
      "why_fails": "Redirect also expects a relative path or internal URL in this context; it's not a rewrite-specific restriction.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    },
    {
      "action": "Setting headers to allow external redirects",
      "why_fails": "Middleware rewrites are fundamentally disallowed for external URLs regardless of headers. The restriction is baked into Next.js's routing logic.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Change the rewrite target to a relative path. If you need to proxy an external URL, create an API route that fetches the external resource and returns it.",
      "success_rate": 0.95,
      "how": "Change the rewrite target to a relative path. If you need to proxy an external URL, create an API route that fetches the external resource and returns it.",
      "condition": "",
      "sources": []
    },
    {
      "action": "Use NextResponse.next() and modify the response headers to forward the request to an external service via a reverse proxy setup (e.g., Nginx or Vercel rewrites in vercel.json).",
      "success_rate": 0.85,
      "how": "Use NextResponse.next() and modify the response headers to forward the request to an external service via a reverse proxy setup (e.g., Nginx or Vercel rewrites in vercel.json).",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "Change the rewrite target to a relative path. If you need to proxy an external URL, create an API route that fetches the external resource and returns it.",
    "Use NextResponse.next() and modify the response headers to forward the request to an external service via a reverse proxy setup (e.g., Nginx or Vercel rewrites in vercel.json)."
  ],
  "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.9,
  "resolvable": "true",
  "first_seen": "2024-03-15",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}