#Astro.rewrite('404') with 410 instead of 404 status

3 messages · Page 1 of 1 (latest)

faint breach
#

When returning return Astro.rewrite("/404") can I render the 404 page but with the 410 status code instead?

molten sonnetBOT
#

Hi @faint breach. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:

#

You can render the 404 page via Astro.rewrite("/404"), but the docs don’t show a way to change the status code of that rewritten response directly through rewrite(). Astro.rewrite() just serves content from another path; status handling is implicit (404 if the target doesn’t exist, 500 on error). [Rewrites]

The documented ways to control status codes are:

  • Set Astro.response.status (and statusText) in the page itself. [Response]
  • Or return your own new Response(...) from the page. [On-demand Response]

However, there is no example or mention of combining Astro.rewrite("/404") with a custom status like 410, and Astro.rewrite() itself does not accept a status parameter. [rewrite()]

So, based on the available docs, you cannot reliably “render /404 but with a 410 status” using Astro.rewrite("/404") alone. You would instead need to:

  • Either implement the 410 response directly (e.g. return new Response(html, { status: 410 })), or
  • Have the /404 page itself set Astro.response.status = 410, but then it will always be 410, not only when rewritten. [response]

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: