{"record":{"id":"f0d0acb55f0aead8","repo":"withastro/astro","slug":"context-rewrite-is-not-available-in-astro","errorCode":null,"errorMessage":"context.rewrite is not available in Astro.","messagePattern":"context\\.rewrite is not available in Astro\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/integrations/netlify/src/index.ts","lineNumber":607,"sourceCode":"\t\t\t\tregion: 'local-dev',\n\t\t\t},\n\t\t\trequestId:\n\t\t\t\ttypeof req.headers['x-nf-request-id'] === 'string'\n\t\t\t\t\t? req.headers['x-nf-request-id']\n\t\t\t\t\t: 'mock-netlify-request-id',\n\t\t\tget cookies(): never {\n\t\t\t\tthrow new Error('Please use Astro.cookies instead.');\n\t\t\t},\n\t\t\tjson: (input) => Response.json(input),\n\t\t\tlog: console.info,\n\t\t\tnext: () => {\n\t\t\t\tthrow new Error('`context.next` is not implemented for serverless functions');\n\t\t\t},\n\t\t\tget params(): never {\n\t\t\t\tthrow new Error(\"context.params don't contain any usable content in Astro.\");\n\t\t\t},\n\t\t\trewrite() {\n\t\t\t\tthrow new Error('context.rewrite is not available in Astro.');\n\t\t\t},\n\t\t};\n\n\t\treturn context;\n\t}\n\n\tlet routes: IntegrationResolvedRoute[];\n\n\treturn {\n\t\tname: '@astrojs/netlify',\n\t\thooks: {\n\t\t\t'astro:config:setup': async ({ config, updateConfig, logger, command }) => {\n\t\t\t\trootDir = config.root;\n\t\t\t\tawait cleanFunctions();\n\n\t\t\t\toutDir = new URL(config.outDir, rootDir);\n\n\t\t\t\tlet session = config.session;","sourceCodeStart":589,"sourceCodeEnd":625,"githubUrl":"https://github.com/withastro/astro/blob/3578d45d34226d63cff3d261c971c221de6794d2/packages/integrations/netlify/src/index.ts#L589-L625","documentation":"Netlify's context.rewrite re-dispatches the request to another function/URL server-side. The Astro adapter does not bridge that mechanism, so the dev Context implements rewrite() as a method that always throws, telling you to use Astro's own rewrite/redirect facilities.","triggerScenarios":"Calling context.rewrite('/other') in a page, endpoint, or middleware while running under the Netlify adapter in local dev.","commonSituations":"Functions code ported from Netlify that used rewrite for A/B routing or fallback pages; attempting rewrites inside on-demand rendered routes.","solutions":["Use Astro.rewrite('/other-path') (Astro core API) for internal re-dispatch","Use Astro.redirect(url, status) when a client redirect is acceptable","Do routing-level fallbacks in middleware with context.redirect/context.rewrite from Astro, never the Netlify Context"],"exampleFix":"// before\nreturn context.rewrite('/fallback');\n// after\nreturn Astro.rewrite('/fallback');","handlingStrategy":"fallback","validationCode":"// Replace Netlify rewrites with Astro's own APIs up front:\nif (needsFallback) {\n  return Astro.rewrite('/fallback'); // or Astro.redirect('/fallback', 302)\n}","typeGuard":"function isNetlifyRewriteAvailable(context: any): boolean {\n  try {\n    return typeof context?.rewrite === 'function' && context.deploy?.context !== 'dev';\n  } catch {\n    return false;\n  }\n}","tryCatchPattern":"try {\n  return context.rewrite('/other');\n} catch {\n  return Astro.rewrite('/other');\n}","preventionTips":["Use Astro.rewrite / Astro.redirect for internal re-dispatch","Keep fallback routing in Astro middleware so it works in dev and prod","Grep the codebase for context.rewrite when adopting the Netlify adapter"],"tags":["netlify","local-dev","context","rewrite","routing"],"backgroundTag":"unsupported-api-stub","analyzedSha":"3578d45d34226d63cff3d261c971c221de6794d2","analyzedAt":"2026-08-18T18:48:03.901Z","contentChangedAt":"2026-08-18T18:48:03.901Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}