#Page giving 404 after build on server
3 messages · Page 1 of 1 (latest)
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:
-
Custom 404 Error Page: Astro allows you to create a custom 404 error page by creating a
404.astroor404.mdfile insrc/pages. This will build to a404.htmlpage. 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) -
Disable Default 404 Route: There's a configuration option
disable404Routein Astro. If you want to use a customsrc/pages/404.astroroute in your project, you need to set this option totrue. Disable 404 Route (https://starlight.astro.build/reference/configuration/#disable404route) -
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)
-
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)
-
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)
- Astro Errors: There are certain Astro errors like
CantRenderPageandFailedToFindPageMapSSRthat 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)