#Redirects on static render
2 messages · Page 1 of 1 (latest)
Astro allows you to specify a mapping of redirects in your Astro configuration with the redirects value. However, Astro does not support regex-based redirects. The key in the redirects object is the route to match and the value is the path to redirect to. You can redirect both static and dynamic routes, but only to the same kind of route.
Here is an example of how you can set up redirects in your Astro configuration:
import { defineConfig } from 'astro/config';
export default defineConfig({
redirects: {
'/old-page': '/new-page'
}
});
In this example, any request to /old-page will be redirected to /new-page.
If you want to redirect dynamic routes, both the new and old routes should contain the same parameters. Here is an example:
{
"/blog/[...slug]": "/articles/[...slug]"
}
In this case, a request to /blog/any-slug will be redirected to /articles/any-slug.
Unfortunately, Astro does not support regex-based redirects, so you cannot create a rule to redirect URLs ending with -old to -new. You would need to specify each redirect individually.