-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Middleware redirect does not work if the page file doesn't exist #7752
Comments
Similar issue occurs when trying to enforce trailing slash from a middleware, e.g. to redirect |
I agree that the middleware must be executed before Astro returns In this case, you can use redirects: // astro.config.mjs
export default defineConfig({
// rest of your config
redirects: {
'/': '/about,
}
}) |
For that particular case it would be fine, but in my real word case I use middleware to determine based on the user accept-language if I should redirect from |
Yeah, I have something similar to that. Hopefully its possible to create a PR for this. |
This seems to be a regression. |
Can I confirm that this was fixed? I see that this was patched in 2.9.5 and 2.9.6, but I am using v2.10.14 and still have the same issue. Rule-out diagnosis:
|
@syahzuan I'd suggest to open a new issue. It's also possible that your environment is different. In fact, the issue was fixed in development. Your case is different because you're using the Cloudflare adapter. |
What version of
astro
are you using?2.9.0
Are you using an SSR adapter? If so, which one?
Not relevant
What package manager are you using?
pnpm
What operating system are you using?
Stackblitz
What browser are you using?
Not relevant
Describe the Bug
I have a project where I always want to redirect the user from the entry point (
/
) to a locale page (/en
).If the
src/pages/index.astro
doesn't exist, this redirect won't happen if we do this via middleware.Is this correct? I searched in the documentation but I haven't found anything.
CleanShot.2023-07-21.at.19.12.41.mp4
What's the expected result?
No need to have an empty index to I can redirect.
Link to Minimal Reproducible Example
https://stackblitz.com/edit/withastro-astro-rfraau?file=src%2Fmiddleware.ts
Participation
The text was updated successfully, but these errors were encountered: