#Page giving 404 after build on server

3 messages · Page 1 of 1 (latest)

molten lynxBOT
#

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

#

There could be several reasons why you're encountering a 404 error on your server after building your Astro project. Here are a few things you can check:

  1. Custom 404 Error Page: Astro allows you to create a custom 404 error page by creating a 404.astro or 404.md file in src/pages. This will build to a 404.html page. Most deploy services will find and use it. If you have a custom 404 page, ensure it's correctly set up. Custom 404 Error Page (https://docs.astro.build/en/basics/astro-pages/#custom-404-error-page)

  2. Disable Default 404 Route: There's a configuration option disable404Route in Astro. If you want to use a custom src/pages/404.astro route in your project, you need to set this option to true. Disable 404 Route (https://starlight.astro.build/reference/configuration/#disable404route)

  3. Middleware Error Pages: Middleware will attempt to run for all on-demand rendered pages, even when a matching route cannot be found. This includes Astro’s default (blank) 404 page and any custom 404 pages. However, it is up to the adapter to decide whether that code runs. Some adapters may serve a platform-specific error page instead. Middleware Error Pages (https://docs.astro.build/en/guides/middleware/#error-pages)

  4. Routing and Redirects: Ensure that your routing and redirects are correctly configured. You can define rules to redirect users to permanently-moved pages in your Astro config, or redirect users dynamically as they use your site. Redirects (https://docs.astro.build/en/guides/routing/#redirects)

  5. Server-side Rendering (SSR): If you're using SSR, ensure that your dynamic routes are correctly generated. If the page is not found, the user will be redirected to a 404 page. Server-side Rendering (https://docs.astro.build/en/guides/cms/strapi/#server-side-rendering)

#
  1. Astro Errors: There are certain Astro errors like CantRenderPage and FailedToFindPageMapSSR that might be causing the issue. If restarting the dev server does not fix the problem, consider filing an issue. Astro can't render the route (https://docs.astro.build/en/reference/errors/cant-render-page/#_top), Astro couldn't find the correct page to render (https://docs.astro.build/en/reference/errors/failed-to-find-page-map-ssr/#_top)

If none of these solutions work, it might be a good idea to check your server logs for any errors or reach out to the Astro community for further assistance.

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