{"record":{"id":"a5621a3b97dd6fcc","repo":"withastro/astro","slug":"forbiddenrewrite-a5621a","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/rewrites/handler.ts","lineNumber":53,"sourceCode":"\tstate: FetchState,\n\tpayload: RewritePayload,\n\t{ routeData, componentInstance, newUrl, pathname }: TryRewriteResult,\n\t{ mergeCookies = false }: { mergeCookies?: boolean } = {},\n): void {\n\tconst pipeline = state.pipeline;\n\tconst oldPathname = state.pathname;\n\n\t// Disallow SSR→prerender rewrites: the prerendered route becomes a\n\t// static HTML file during build and isn't available in the server\n\t// manifest. Allow i18n fallback routes as an exception.\n\tconst isI18nFallback = routeData.fallbackRoutes && routeData.fallbackRoutes.length > 0;\n\tif (\n\t\tpipeline.manifest.serverLike &&\n\t\t!state.routeData!.prerender &&\n\t\trouteData.prerender &&\n\t\t!isI18nFallback\n\t) {\n\t\tthrow new AstroError({\n\t\t\t...ForbiddenRewrite,\n\t\t\tmessage: ForbiddenRewrite.message(state.pathname, pathname, routeData.component),\n\t\t\thint: ForbiddenRewrite.hint(routeData.component),\n\t\t});\n\t}\n\n\tstate.routeData = routeData;\n\tstate.componentInstance = componentInstance;\n\tif (payload instanceof Request) {\n\t\tstate.request = payload;\n\t} else {\n\t\tstate.request = copyRequest(\n\t\t\tnewUrl,\n\t\t\tstate.request,\n\t\t\trouteData.prerender,\n\t\t\tpipeline.logger,\n\t\t\tstate.routeData!.route,\n\t\t);","sourceCodeStart":35,"sourceCodeEnd":71,"githubUrl":"https://github.com/withastro/astro/blob/d081033d5fe8e8a68c4bbbad4af9d2deb9c74bca/packages/astro/src/core/rewrites/handler.ts#L35-L71","documentation":"ForbiddenRewrite: in 'server' output, Astro.rewrite() tried to route an on-demand (SSR) request to a prerendered route. Prerendered routes compile to static HTML at build time and are not present in the server manifest, so they cannot be served at runtime — the rewrite is forbidden (i18n fallback routes excepted).","triggerScenarios":"Calling Astro.rewrite('/static-page') from an SSR route where /static-page is prerendered; a prerendered destination route while output is 'server'; middleware rewriting on-demand requests to prerendered pages.","commonSituations":"Migrating pages between prerendered and on-demand; using Astro.rewrite to route to a page intended to be static; forgetting that output:'server' still prerenders pages without `export const prerender = false` being absent (i.e. the target defaulted to prerender).","solutions":["Add `export const prerender = false` to the destination component so it renders on demand.","Use Astro.redirect() instead of Astro.rewrite() when the target must stay static (a real navigation, not an internal rewrite).","Re-check whether the destination route is in the SSR server manifest."],"exampleFix":"// before — destination pages/about.astro is prerendered\nAstro.rewrite('/about');\n\n// after — make the destination on-demand\n// pages/about.astro\nexport const prerender = false;","handlingStrategy":"validation","validationCode":"function canRewriteTo(fromPrerender: boolean, toPrerender: boolean, serverLike: boolean, isI18nFallback: boolean): boolean {\n  if (serverLike && !fromPrerender && toPrerender && !isI18nFallback) return false;\n  return true;\n}\n// before Astro.rewrite, ensure the destination is on-demand","typeGuard":null,"tryCatchPattern":"try {\n  Astro.rewrite(target);\n} catch (e) {\n  if (e instanceof AstroError && e.code === 'ForbiddenRewrite') {\n    return Astro.redirect(target); // fall back to a real navigation\n  }\n  throw e;\n}","preventionTips":["Mark rewrite destinations with `export const prerender = false`.","Prefer Astro.redirect() when the target must remain static.","Document which routes are on-demand vs prerendered in an i18n or routing map."],"tags":["rewrite","ssr","prerender","routing","i18n"],"backgroundTag":null,"analyzedSha":"d081033d5fe8e8a68c4bbbad4af9d2deb9c74bca","analyzedAt":"2026-08-12T13:37:29.035Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}