301 Redirect an Indexed Subdomain to Your Main Domain

Google indexed your pages on the wrong host, like test.example.com/slug instead of example.com/slug. This guide shows how to move them over with 301 redirects, verify the setup, and monitor the move until Google is done.

Don't want to touch DNS and server configs? We can do the move for you →

Why Redirect Instead of Deleting or Using the Removals Tool

  • A 301 redirect moves the URL: Google recrawls the old URL, follows the redirect and consolidates ranking signals and links onto the new URL. Visitors with old links land on the right page.
  • Deleting throws the signals away: the old URLs return errors and eventually drop out, but nothing is passed to your main domain. The live pages have to earn their rankings from scratch.
  • The Removals tool only hides URLs: it blocks them from search results for about six months and transfers nothing. It is useful for urgent cases (leaked private content), not for moving pages.
  • Duplicates split your signals: while the same content lives on two hosts, Google has to pick one, and it may pick the wrong one.

1Find Your Canonical Host

Decide where the pages should live: example.com or www.example.com. Check which one actually serves your site:

curl -sI https://example.com/ | head -1
curl -sI https://www.example.com/ | head -1
  • One returns 200, the other 301 to it: the 200 host is your canonical host. Redirect to that one directly.
  • Both return 200: you have a second duplicate problem. Pick one host and 301 the other to it as well.
  • Watch for empty 200s: a reverse proxy can answer a host it has no route for with an empty 200. Check the body too: curl -s https://www.example.com/ | wc -c. A 0 means a blank page Google could index.

Always redirect straight to the final host. A chain like test → www → example.com works, but a single hop is cleaner.

2Collect the Indexed URLs on the Wrong Host

Google Search Console has no single export of every indexed URL, so combine these sources:

  • Performance report: filter Page by "URLs containing" test.example.com and export. This lists URLs that received impressions.
  • Pages report: open the indexed pages list for the host and export it (the export is capped at 1,000 rows per view).
  • site: search: site:test.example.com as a sanity check.

Tip: a Domain property (example.com) in Search Console covers every subdomain, so you can inspect both the old and the new URLs in one place.

3Subdomain Already Deleted? Bring It Back

If you removed the subdomain from DNS, Google only gets DNS errors. It will drop the URLs eventually, but nothing is passed to your main domain and nothing can redirect. Recreate the DNS record and point it at something that does one job: send 301s. No app, no content.

  • Own server: an A/AAAA record for test pointing to your web server or reverse proxy.
  • Cloudflare: a proxied placeholder record (see Step 4).

The host needs a valid TLS certificate. The indexed URLs are usually https://, and a certificate error stops Google before it sees the redirect.

4Set Up the 301 Redirect

Map every path 1:1: test.example.com/slug → example.com/slug. Pick your stack:

Cloudflare

  1. 1. DNS → add an AAAA record named test with content 100:: and proxy status Proxied.
  2. 2. Rules → Redirect Rules → Create rule. When: Hostname equals test.example.com.
  3. 3. Then: Dynamic redirect with this expression, status code 301, preserve query string:
concat("https://example.com", http.request.uri.path)

Cloudflare issues the certificate automatically.

nginx

server {
    listen 80;
    listen 443 ssl;
    server_name test.example.com;

    ssl_certificate     /etc/letsencrypt/live/test.example.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/test.example.com/privkey.pem;

    return 301 https://example.com$request_uri;
}

$request_uri keeps the path and query string. Get the certificate with certbot before enabling the 443 listener.

Caddy

test.example.com {
	redir https://example.com{uri} permanent
}

Caddy gets the certificate automatically. Behind an edge proxy that terminates TLS, use http://test.example.com as the site address in the inner Caddyfile. The redirect target stays https://.

Vercel

Add test.example.com to your project's domains and set it to redirect to example.com, or use a host-based redirect in vercel.json:

{
  "redirects": [
    {
      "source": "/:path*",
      "has": [{ "type": "host", "value": "test.example.com" }],
      "destination": "https://example.com/:path*",
      "permanent": true
    }
  ]
}

"permanent": true sends a 308, which Google treats the same as a 301.

No live equivalent? Redirect a URL to the closest matching page, or let it return 410. Don't send everything to the homepage. Google treats mass homepage redirects as soft 404s.

5Don't Sabotage the Redirect

  • Don't block the old host in robots.txt. A Disallow stops Google from crawling the old URLs, so it never sees the redirects.
  • Don't add noindex. A redirect response has no page for a noindex to live on. The redirect alone is the signal.
  • Keep the redirects live. Google recommends keeping site-move redirects for at least a year. A redirect-only host costs next to nothing to keep running.

6Verify the Redirects

Check a single URL:

curl -sI https://test.example.com/slug1

You want exactly one response with status 301 (or 308) and location: https://example.com/slug1. To check every URL from Step 2, put them in old-urls.txt, one per line:

while read -r url; do
  curl -s -o /dev/null -w "%{http_code} %{redirect_url} $url\n" "$url"
done < old-urls.txt

Every line should start with 301 and show the matching new URL.

7Help Google Find the Redirects Faster

Google recrawls old URLs on its own schedule, which can be slow for a host it rarely visits. Speed it up with a temporary sitemap that lists the old URLs:

  1. 1. Create sitemap-old-urls.xml with the old test.example.com URLs.
  2. 2. Host it on your main domain. The old host only redirects, so it cannot serve the file itself.
  3. 3. Submit it in your Domain property in Search Console. Because the property covers both hosts, Google accepts the cross-host URLs.
  4. 4. Remove the sitemap once the old URLs show "Page with redirect".

Make sure the new URLs are in your regular sitemap too.

8Monitor Until Every Old URL Shows "Page with Redirect"

In Search Console, "Page with redirect" is usually listed as a reason a page is not indexed. During a move, it is the status you want for the old URLs. The move is done when:

  • • Every old URL shows Page with redirect in URL Inspection.
  • • Every new URL shows URL is on Google.
  • • site:test.example.com returns no results.

Expect a few weeks for small sites and up to a few months for hosts Google rarely crawls. Checking hundreds of URLs by hand is tedious. MyURLMonitor inspects them on a schedule and shows how many have moved.

Frequently Asked Questions

Does a 301 remove the old subdomain URLs from Google?

Yes, once Google recrawls them. It follows the redirect, indexes the new URL and drops the old one.

Can I redirect www to non-www (or the other way) the same way?

Yes. Pick one canonical host, 301 the other permanently, and make sure your canonical tags and internal links use the canonical host.

Why are my staging URLs indexed in the first place?

Usually a robots.txt block that hid the noindex, or links pointing to the staging host. Read why staging sites get indexed despite noindex →

How long should I keep the redirects?

At least a year, and longer if old links to the subdomain still exist on other sites.

Need It Done for You?

Our SEO migration service finds every misplaced URL, sets up and verifies the redirects on your stack, and monitors the move until Google has finished. Or do it yourself and track the progress with MyURLMonitor.

301 Redirect an Indexed Subdomain to Your Main Domain - MyURLMonitor Help