#Is there a way to have dynamic redirects in astro.config.js?
7 messages · Page 1 of 1 (latest)
Hi @zinc sparrow. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
Astro does support redirects in the astro.config.mjs file, and it also supports dynamic routes. However, according to the Astro documentation (https://docs.astro.build/en/guides/routing#redirects) and the Github issue (https://github.com/withastro/astro/issues/8639), dynamic redirects are allowed as long as both the new and old routes contain the same parameters.
Here is an example from the documentation:
import { defineConfig } from 'astro/config';
export default defineConfig({
redirects: {
"/blog/[...slug]": "/articles/[...slug]"
}
});
However, it seems there are some issues with dynamic redirects as reported in the Github issue. The user reported errors when trying to use dynamic redirects, even when the new and old routes contained the same parameters.
So, while theoretically, it should be possible to use dynamic redirects in the way you're suggesting, there may be some issues that need to be resolved. You might want to keep an eye on the Github issue for updates or potential workarounds.
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
@zinc sparrow kapa.ai is still learning and improving, please let us know how it did by reacting below
@feral ridge How should I write the syntax for my case? I've tried as showed before and it wasn't working.
Let me check the knowledge base for you. One moment! :books:
I'm sorry for the confusion, but based on the provided knowledge sources, there isn't a specific example or guideline on how to implement dynamic redirects with language parameters in Astro. The knowledge sources do not provide enough information to confidently provide a solution for your specific case.