Skip to content

Middleware doesn't redirect and serves 404 when a page doesn't exist #8226

@syahzuan

Description

@syahzuan

Astro info

Astro version            v2.10.14
Package manager          npm
Platform                 linux
Architecture             x64
Adapter                  Couldn't determine.
Integrations             @astrojs/mdx, @astrojs/sitemap

What browser are you using?

Firefox, Chrome

Describe the Bug

This is the same issue in #7752, released in #7851 #7854, but the issue isn't fixed.

I am trying to redirect / (which does not exist) to the localized content (/en or /zh etc), but Astro returns 404 instead of running the middleware.

The bug is reproduced at the link below.

What's the expected result?

Middleware should run before Astro returns 404.

Link to Minimal Reproducible Example

https://stackblitz.com/edit/withastro-astro-stgbcz?file=src%2Fmiddleware.js

Participation

  • I am willing to submit a pull request for this issue.

Metadata

Metadata

Assignees

Labels

feat: error pagesRelated to 404 and 500 handling (scope)feat: middlewareRelated to middleware (scope)feat: ssrRelated to SSR (scope)

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions