How to Change Your Astro Site's Domain Without Losing Google Rankings
Moving to a new domain is safe if every old address redirects to its new one with a 301. How to set that up on Cloudflare, Netlify and in Astro, then tell Google.
Tested on Astro 7.4

In this guide
Changing your domain is the one move that can quietly erase years of Google rankings. It’s also safe, as long as every old address sends people and Google to the matching new one. On a static site, that’s a short job. Here’s how.
The one rule
Every old address must redirect to the same page at the new address with a 301 status. Not to the home page. To the same page. old.com/about/ goes to new.com/about/. Google follows the redirect and moves the ranking across.
Step 1: Redirect the whole old domain
Set this up at the host or at the DNS level, so it covers every page at once.
Cloudflare. Add the old domain to your Cloudflare account. Then under Rules, make a redirect rule: when the hostname is the old domain, redirect to https://new.com followed by the same path, with status 301. Cloudflare’s rule builder has a “dynamic” option that keeps the path. We use a rule like this to send www.astrobeginner.com to astrobeginner.com.
Netlify. Add the old domain to the same site, then put a _redirects file in your public/ folder:
https://old.com/* https://new.com/:splat 301!
The :splat keeps the path. The ! makes it win over any real page.
GitHub Pages. It can’t redirect a whole domain. Point the old domain at Cloudflare or Netlify and use one of the two options above.
Step 2: Redirect any pages that changed address
If you also renamed pages during the move, add those in Astro. In astro.config.mjs:
export default defineConfig({
redirects: {
'/old-page/': '/new-page/',
'/blog/2024/first-post/': '/posts/first-post/',
},
});
We added one of these to a fresh Astro 7.4 project and built it. Astro wrote a small HTML file at the old address that sends the browser to the new one.
Step 3: Update your site’s own links
Search your project for the old domain and replace it. Check:
siteinastro.config.mjs. This feeds your sitemap and canonical links.- Hard-coded links in content and layouts.
public/robots.txt, if it names your sitemap.
Build and search dist for the old domain. It should appear nowhere.
Step 4: Tell Google
- Add the new domain in Google Search Console and verify it.
- In the old domain’s property, open Settings, then Change of address. Pick the new property. Google checks that your redirects work, then starts moving rankings over.
- Submit the new sitemap under Sitemaps.
Bing has the same tool in Bing Webmaster Tools. Do it there too. ChatGPT’s web search uses Bing.
Step 5: Fix the links you control
Update your social profiles, your email signature, and any sites you own that link to the old domain. Links you don’t control keep working because of step 1.
Step 6: Wait, and watch
Rankings usually move within two to four weeks. Watch Search Console for the new domain’s pages appearing and the old domain’s dropping. A dip for a week or two is normal. A dip that lasts months means a redirect is missing. Test a few old addresses by hand and check they land on the right page.
Where to go next
- Astro SEO guide for the rest of getting found.
- How to add a sitemap so Google sees every new address.
Frequently asked questions
Will I lose my Google rankings?
Not if you redirect every old page to its new one with a 301 and tell Search Console about the move. Rankings usually carry over within a few weeks. Skip the redirects and you start from zero.
What's the difference between 301 and 302?
A 301 says "moved for good" and Google passes the ranking to the new address. A 302 says "temporary" and Google keeps the old one. For a domain change, you want 301.
How long should I keep the redirects?
As long as you own the old domain, ideally. A year at minimum. People have old links in bookmarks and emails for a long time.
Stuck on a step?
Check the common errors guide, look up a word in the glossary, or ask the friendly people in the official Astro and EmDash Discords. How to ask so people can help.
