An Astro redirect page is the small HTML file a static build writes for every entry in redirects, using a <meta http-equiv="refresh"> tag to send visitors on. Since Astro 7.4 you can replace Astro’s built-in version with your own design: enable experimental.redirectPage and create src/pages/3xx.astro, which Astro renders once per redirect with from, to, status and delay as props.
Key Takeaways
- Needs Astro 7.4+ and
experimental: { redirectPage: true }.- Create
src/pages/3xx.astro; it receivesfrom,to,statusanddelayinAstro.props.- The page must include a
<meta http-equiv="refresh">tag pointing atto, or the redirect stops working.- It applies to redirects a static build generates; on-demand redirects still send a real HTTP
Locationheader.
Why static redirects are HTML pages
On a static host, Astro can’t send a 301 status code. When you define a redirect in config, the build writes dist/old-path/index.html containing a meta refresh, a noindex robots tag, a canonical link and a plain link to the target. That default page is unstyled and says very little, which is fine for crawlers but looks broken to a human who lands on it during the one second it’s visible, or during two seconds for a 302.
Hosts like Netlify and Cloudflare Pages can also read a _redirects file and send real status codes, and some adapters write that file for you. The custom page is for everything that still falls back to HTML. The Astro redirects tip covers the config side in detail.
Enable the flag and add 3xx.astro
// astro.config.mjs
import { defineConfig } from 'astro/config';
export default defineConfig({
redirects: {
'/old-blog/[slug]': '/blog/[slug]',
'/pricing-2025': { status: 302, destination: '/pricing/' },
},
experimental: {
redirectPage: true,
},
});
Then create the page. It lives in src/pages/ but isn’t served at /3xx/; Astro uses it as a template:
---
// src/pages/3xx.astro
import BaseLayout from '../layouts/BaseLayout.astro';
const { from, to, status, delay } = Astro.props;
---
<BaseLayout title="This page has moved">
<meta slot="head" http-equiv="refresh" content={`${delay};url=${to}`} />
<meta slot="head" name="robots" content="noindex" />
<link slot="head" rel="canonical" href={to} />
<main>
<h1>This page has moved</h1>
<p>
<code>{from}</code> now lives at <a href={to}>{to}</a>.
</p>
{status === 302 && <p>This is a temporary move. Taking you there now.</p>}
</main>
</BaseLayout>
Adjust the slot="head" part to however your layout accepts extra head tags. If it doesn’t have a head slot, write the full <html> document directly in 3xx.astro.
The four props
| Prop | Value |
|---|---|
from |
The pathname being redirected, for example /old-blog/hello |
to |
The destination URL |
status |
The configured status code, such as 301 or 302 |
delay |
Seconds before the refresh fires: 2 for a 302, 0 otherwise |
Use delay as given in the meta tag so permanent redirects stay instant. A visible message is still useful: some visitors have meta refresh disabled, and a link is their way forward.
Rules that keep it working
The meta refresh is the redirect in a static build. Astro warns during the build if your page is missing it, so treat that warning as an error.
Middleware doesn’t run when Astro renders the redirect page. It already ran for the original request, and running it again could cause a redirect loop. Don’t depend on Astro.locals values set by middleware here.
If 3xx.astro throws while rendering, Astro logs the error and falls back to its built-in page for that redirect, so a bug won’t fail your build or strand visitors. Check the build log after adding the page.
Keep the page light. It’s shown for zero to two seconds, so skip analytics scripts, large images and client islands. Keep the noindex tag and the canonical link to to from the built-in page; they help search engines consolidate signals on the new URL.
When the page isn’t used
On-demand routes and server output send a real Location header with the configured status, which browsers follow before rendering any body, so the template doesn’t apply. It also doesn’t replace your custom 404 page, which handles URLs that have no redirect at all. For moving a whole site, pair redirects with the site migration SEO checklist. The experimental redirect page docs track any changes to the flag, and our pages and routing docs show where src/pages/ fits in the Komal Astro themes, where 3xx.astro can reuse the theme’s base layout.
FAQ
How do I redirect a page in Astro?
Add an entry to redirects in astro.config.mjs, such as '/old': '/new'. Static builds write an HTML page with a meta refresh; server-rendered routes return a 301 by default, or the status you set.
Can I style the Astro redirect page?
Yes, from Astro 7.4. Enable experimental.redirectPage and create src/pages/3xx.astro. Astro renders it for every redirect, passing from, to, status and delay.
Does a meta refresh redirect hurt SEO?
An instant meta refresh (delay 0) is treated by Google much like a permanent redirect. Real 301 responses from your host are still the stronger signal, so use host redirect rules where you can.
Why does my 302 redirect page wait two seconds?
Astro sets delay to 2 for 302 redirects and 0 for all others, matching its built-in page. You can ignore the prop and hardcode a value, but keep permanent redirects at zero.