I understand you're concerned about maintaining stable image URLs during your migration to Astro. Let me help you with handling image redirects in Astro.
Setting Up Image Redirects in Astro
When migrating from WordPress to Astro, maintaining stable image URLs is important for preserving external links. Here are your options:
1. Use Configured Redirects
Astro provides a built-in way to set up redirects in your astro.config.mjs file:
import { defineConfig } from "astro/config";
export default defineConfig({
redirects: {
"/old-image-path.jpg": "/new-image-path.jpg",
"/old-blog/image.png": "/new-blog/image.png"
}
});
This approach works well for static sites and SSR sites alike Redirects Configuration.
2. Place Images in the Public Folder
For the most stable approach, place your critical images in the public/ directory. Files in this directory maintain their exact paths and filenames in the built site:
public/images/your-quirky-image.jpg → /images/your-quirky-image.jpg
This is the most straightforward way to ensure image URLs remain stable Using Images from a CMS or CDN.
3. Use Platform-Specific Redirects
If you're deploying to platforms like Netlify or Cloudflare, you can also use their platform-specific redirect files:
Important Considerations