🔥 All-Access Pass — $199 USD (Regular $499) · Unlock all 2,836 Astro themes ➔
komal.nakrani
Get All-Access Pass ($199)
ThemesCategoriesDocsBlogTips & TricksPricingGet All-Access Pass ($199)
SEO••By Komal Nakrani

Add an Astro Site to Google Search Console

Add an Astro site to Google Search Console: verify with a DNS record, an HTML file in public/ or a meta tag, submit sitemap-index.xml and inspect your first URLs.

#Astro#SEO#Google Search Console#Sitemap

To add an Astro site to Google Search Console, create a property, verify ownership, then submit your sitemap. The most complete option is a Domain property verified with a DNS TXT record, which covers every subdomain and protocol. If you cannot edit DNS, use a URL-prefix property and verify with Google’s HTML file placed in public/, or a google-site-verification meta tag in your base layout’s <head>.

Key Takeaways

  • A Domain property (DNS verification) covers www, non-www, HTTP and HTTPS in one place.
  • For a URL-prefix property, an HTML file in public/ is the easiest Astro method.
  • Submit sitemap-index.xml after verification; @astrojs/sitemap generates it.
  • Use URL Inspection to request indexing for a few key pages after launch.

Option 1: Domain property with DNS

  1. In Search Console, choose “Add property” and pick Domain.
  2. Enter example.com without https:// or www.
  3. Copy the TXT record Google shows, starting with google-site-verification=.
  4. Add it at your DNS provider as a TXT record on the root domain.
  5. Return to Search Console and click Verify.

If your domain uses Cloudflare DNS, the record is under DNS, Records, Add record, type TXT, name @. Verification can take a few minutes after the record is saved. Nothing changes in the Astro project, and the property survives redesigns and host changes. The custom domain tip covers the rest of the DNS setup.

Option 2: URL-prefix with an HTML file

Choose URL prefix, enter the exact origin, such as https://www.example.com/, and pick the HTML file method. Download the file and put it in public/:

public/
  google1234567890abcdef.html

Astro copies public/ into the build unchanged, so after the next deploy the file is served at https://www.example.com/google1234567890abcdef.html. Check that URL in a browser, then click Verify. Keep the file in the project; removing it can unverify the property later.

Option 3: URL-prefix with a meta tag

The meta tag method puts the token in your head component. Read it from an environment variable so the token is not hard-coded in a theme you reuse:

---
// src/components/BaseHead.astro
const verification = import.meta.env.PUBLIC_GOOGLE_SITE_VERIFICATION;
---
{verification && <meta name="google-site-verification" content={verification} />}
# .env
PUBLIC_GOOGLE_SITE_VERIFICATION=abc123yourtoken

Set the same variable in your host’s build settings, since .env is usually not committed. The PUBLIC_ prefix makes it available in components; our environment variables guide explains the rules. The tag must be on the homepage at least.

Submit the sitemap

With @astrojs/sitemap installed and site set, every build writes sitemap-index.xml:

  1. Open Sitemaps in the left menu.
  2. Enter sitemap-index.xml and submit.
  3. The status should change to Success, with the number of discovered URLs.

Search Console reads the index file and the sitemap-N.xml files it points to. Add a Sitemap: line to robots.txt too, so other search engines find it; the sitemap tip shows both.

First checks after launch

  • URL Inspection. Paste your homepage and a key page, run a live test, and request indexing.
  • Pages report. After a few days, look for “Excluded by noindex tag” or “Page with redirect” on pages that should be indexed. Trailing slash mismatches often show up here.
  • Core Web Vitals report. Fills in once enough Chrome users visit; until then, use lab tools.

If many URLs show “Alternate page with proper canonical tag”, check that your canonical URLs match your trailingSlash setting; see the canonical URLs tip. The deploy docs cover publishing a theme from our catalog before you verify.

FAQ

Which Search Console verification method is best for Astro?

DNS verification of a Domain property is best because it covers all versions of the site and does not depend on files in the project. Use the HTML file in public/ if you cannot change DNS.

Where do I put the Google verification HTML file in Astro?

In the public/ folder at the project root. Astro copies it to the root of the built site unchanged.

How long does it take Google to index a new Astro site?

Usually days to a few weeks. Submitting the sitemap and requesting indexing for key URLs speeds up discovery, but Google decides when to crawl and index.

Do I need to resubmit the sitemap after every deploy?

No. Google rechecks submitted sitemaps on its own. Resubmit only if the sitemap URL changes.