Free Astro tutorials for complete beginners.

Beginner's Guide to Astro

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

Cover image for How to Change Your Astro Site's Domain Without Losing Google Rankings
In this guide
  1. The one rule
  2. Step 1: Redirect the whole old domain
  3. Step 2: Redirect any pages that changed address
  4. Step 3: Update your site’s own links
  5. Step 4: Tell Google
  6. Step 5: Fix the links you control
  7. Step 6: Wait, and watch
  8. Where to go next
  9. Frequently asked questions

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.

Search your project for the old domain and replace it. Check:

  • site in astro.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

  1. Add the new domain in Google Search Console and verify it.
  2. 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.
  3. 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.

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

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.

Keep reading

  1. How to Register a Domain Name and Connect It to Your Astro Site

    Buy a domain for about $11 a year, then point it at Cloudflare or Netlify. We did this for astrobeginner.com, and these are the exact steps.

    Tutorials, 8 minute read, November 8, 2026

  2. How to Add Google Analytics to an Astro Site (and a Simpler Option)

    Paste Google's tag into your Astro layout with one small change, is:inline, and it works on every page. Or use Cloudflare Web Analytics, which needs no cookie banner.

    Tutorials, 6 minute read, November 8, 2026

  3. How to Add a Contact Form to an Astro Site (No Server Needed)

    A static site can't receive form submissions on its own. A free form service can. Here's a working contact form in ten lines, with spam protection built in.

    Tutorials, 7 minute read, November 8, 2026

Try "blog", "deploy" or "EmDash".