{"record":{"id":"75bedbbf4cc93b0d","repo":"withastro/astro","slug":"forbiddenrewrite","errorCode":"ForbiddenRewrite","errorMessage":"You tried to rewrite the on-demand route '${from}' with the static route '${to}', when using the 'server' output. \n\nThe static route '${to}' is rendered by the component\n'${component}', which is marked as prerendered. This is a forbidden operation because during the build, the component '${component}' is compiled to an\nHTML file, which can't be retrieved at runtime by Astro.","messagePattern":"You tried to rewrite the on-demand route '(.+?)' with the static route '(.+?)', when using the 'server' output\\. \n\nThe static route '(.+?)' is rendered by the component\n'(.+?)', which is marked as prerendered\\. This is a forbidden operation because during the build, the component '(.+?)' is compiled to an\nHTML file, which can't be retrieved at runtime by Astro\\.","errorType":"exception","errorClass":"AstroError","httpStatus":null,"severity":"error","filePath":"packages/astro/src/core/middleware/sequence.ts","lineNumber":78,"sourceCode":"\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tconst request =\n\t\t\t\t\t\t\t\thandleContext.request.method === 'GET' || handleContext.request.method === 'HEAD'\n\t\t\t\t\t\t\t\t\t? handleContext.request\n\t\t\t\t\t\t\t\t\t: handleContext.request.clone();\n\t\t\t\t\t\t\tconst newUrl =\n\t\t\t\t\t\t\t\tpayload instanceof URL ? payload : new URL(payload, handleContext.url.origin);\n\t\t\t\t\t\t\tnewRequest = copyRequest(newUrl, request, false, state.logger, routeData.route);\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\t// This is a case where the user tries to rewrite from a SSR route to a prerendered route (SSG).\n\t\t\t\t\t\t// This case isn't valid because when building for SSR, the prerendered route disappears from the server output because it becomes an HTML file,\n\t\t\t\t\t\t// so Astro can't retrieve it from the emitted manifest.\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\tmanifest.serverLike === true &&\n\t\t\t\t\t\t\thandleContext.isPrerendered === false &&\n\t\t\t\t\t\t\trouteData.prerender === true\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\tthrow new AstroError({\n\t\t\t\t\t\t\t\t...ForbiddenRewrite,\n\t\t\t\t\t\t\t\tmessage: ForbiddenRewrite.message(\n\t\t\t\t\t\t\t\t\thandleContext.url.pathname,\n\t\t\t\t\t\t\t\t\tpathname,\n\t\t\t\t\t\t\t\t\trouteData.component,\n\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\thint: ForbiddenRewrite.hint(routeData.component),\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tcarriedPayload = payload;\n\t\t\t\t\t\thandleContext.request = newRequest;\n\t\t\t\t\t\thandleContext.url = new URL(newRequest.url);\n\t\t\t\t\t\thandleContext.params = getParams(routeData, pathname);\n\t\t\t\t\t\thandleContext.routePattern = routeData.route;\n\t\t\t\t\t\tsetOriginPathname(\n\t\t\t\t\t\t\thandleContext.request,\n\t\t\t\t\t\t\toldPathname,","sourceCodeStart":60,"sourceCodeEnd":96,"githubUrl":"https://github.com/withastro/astro/blob/157c500c38faa7ecf1251adbaeefcd109470d75c/packages/astro/src/core/middleware/sequence.ts#L60-L96","documentation":"AstroErrorData.ForbiddenRewrite is thrown when a rewrite targets a prerendered route from an on-demand (SSR) route while the manifest is server-like. During build, prerendered routes compile to plain HTML files and disappear from the server manifest, so the running server has no component to render for them — the rewrite is impossible by construction, not merely unsupported.","triggerScenarios":"Astro.rewrite('/prerendered-page') or next('/prerendered-page') from an SSR route, when the target has `export const prerender = true` and the project builds with output 'server'.","commonSituations":"Marking marketing/docs pages prerendered for performance while app pages rewrite into them; migrating a site from static to server output where old rewrites now point at pages that became static; shared routing tables that mix both kinds of routes.","solutions":["Remove `export const prerender = true` from the target route so it stays renderable on demand","Redirect instead of rewriting: return Astro.redirect(target) — static HTML files are still served, so the URL change is safe","If the target must stay prerendered, link to it or fetch its content server-side instead of rewriting"],"exampleFix":"// before\nreturn Astro.rewrite('/prerendered-page');\n\n// after\nreturn Astro.redirect('/prerendered-page');","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"import { AstroError } from 'astro/errors';\ntry {\n  return await Astro.rewrite(target);\n} catch (err) {\n  if (err instanceof AstroError && err.code === 'ForbiddenRewrite') {\n    // target is prerendered — redirect instead; the static file is still served\n    return Astro.redirect(target);\n  }\n  throw err;\n}","preventionTips":["Before rewriting, confirm the target route does not export prerender = true","Prefer redirects toward prerendered pages — they work regardless of output mode","When enabling prerender on a route, grep the codebase for rewrites pointing at it"],"tags":["rewrite","prerender","ssr","routing","build-output"],"backgroundTag":"ssr-rewrite-to-prerendered-route","analyzedSha":"157c500c38faa7ecf1251adbaeefcd109470d75c","analyzedAt":"2026-08-18T18:48:03.901Z","contentChangedAt":"2026-08-18T18:48:03.901Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}