{"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/d081033d5fe8e8a68c4bbbad4af9d2deb9c74bca/packages/integrations/netlify/src/index.ts#L589-L625","documentation":"In the dev mock context, `rewrite` is a function that always throws `'context.rewrite is not available in Astro.'`. Astro performs rewrites via `Astro.redirect` / returning a `Response` with the rewritten target, or `return new Request(...)`. Netlify's `context.rewrite()` API is not bridged in the Astro adapter.","triggerScenarios":"Calling `context.rewrite(url)` in an Astro handler or middleware in dev. Reusing Netlify Edge Function code that performs rewrites via `context.rewrite`.","commonSituations":"Porting Netlify rewrite logic into Astro. Middleware that rewrites instead of redirecting through Astro's API.","solutions":["Use `Astro.redirect(to)` for HTTP redirects.","For internal rewrites, return a `Response` or `Request` from the handler, or use `Astro.rewrite` if available in your Astro version.","Use `_redirects` / `netlify.toml` redirects for path-level rewrites handled at the edge."],"exampleFix":"// before\nreturn context.rewrite('/new-path');\n\n// after\nreturn Astro.redirect('/new-path');","handlingStrategy":"fallback","validationCode":"function rewriteOrRedirect(Astro: any, to: string) {\n  if (typeof (Astro as any).rewrite === 'function') return (Astro as any).rewrite(to);\n  return Astro.redirect(to);\n}","typeGuard":"function hasAstroRewrite(Astro: any): Astro is { rewrite: (input: string | URL | Request) => Response } {\n  return typeof Astro?.rewrite === 'function';\n}","tryCatchPattern":null,"preventionTips":["Use `Astro.redirect` for HTTP redirects.","Use `_redirects` / `netlify.toml` for edge rewrites.","Return a `Response`/`Request` from handlers for internal rewrites."],"tags":["netlify","dev-server","rewrite","deprecation"],"backgroundTag":null,"analyzedSha":"d081033d5fe8e8a68c4bbbad4af9d2deb9c74bca","analyzedAt":"2026-08-12T13:37:29.035Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}