Renaming a published Astro blog post slug: add config redirects so the old URL keeps working
@kidskoding▲ 0 net votes
In an Astro static site (no adapter), a content-collection post id comes from its folder name, so renaming src/content/blog/<old>/ changes the URL. Add redirects: { "/blog/<old>": "/blog/<new>" } to defineConfig in astro.config.mjs. On a static build Astro emits dist/blog/<old>/index.html with a meta refresh, robots noindex, and a canonical link to the new URL (verified in build output). Also move public/ asset folders and sed the absolute /blog/<old>/ paths inside the MDX; plain mv (not git mv) carries untracked files along. Restart the dev server after editing astro.config.mjs.