Static rules
- Use
public/robots.txt- Check
- Confirm the host publishes the file at
/robots.txt
Serve robots.txt from Astro’s public directory or generate it from the configured site URL, then verify the deployed rules.
For a static Astro site, put a plain-text robots.txt in public/; Astro copies it to the root of the built site. If the sitemap URL depends on site in astro.config.mjs, generate /robots.txt with a src/pages/robots.txt.ts endpoint and return text/plain. Check the production response: robots rules control crawling, not access or guaranteed deindexing.
Four quick questions, then a straight answer.
From your answers, this is quietly costing you traffic and nobody has the hours to chase it. Scaplet finds every affected page, drafts the fixes and tracks how AI answers mention you.
A data platform shipped 46 fixes without a ticket.
This looks handled. Re-check after a redesign, a migration or a big content push; that is when it breaks.
Your site is small and you have the time. Work through the steps on this page, starting with the pages that get the most traffic.
public/robots.txt/robots.txtsrc/pages/robots.txt.ts endpointAstro's project-structure guide says files in public/ are copied into the build folder untouched, and its own example tree lists public/robots.txt. A generated endpoint is useful when you want to derive the sitemap URL from Astro’s configured site value and avoid manually keeping two URLs in sync.
Keep the file small and specific. A broad Disallow: / can block crawling across the whole site, while a rule for /preview/ only makes sense if that path exists and should not be fetched. Robots rules are public instructions for cooperative crawlers; they do not protect private routes, and another crawler may ignore them.
User-agent: *
Allow: /
Sitemap: https://example.com/sitemap-index.xmlsite value must be your canonical production origin. This endpoint example mirrors the integration’s documented pattern; use the final public URL your build actually emits.import type { APIRoute } from 'astro'
export const GET: APIRoute = ({ site }) => {
if (!site) throw new Error('Set site in astro.config.mjs')
const sitemap = new URL('sitemap-index.xml', site)
const body = `User-agent: *\nAllow: /\n\nSitemap: ${sitemap.href}\n`
return new Response(body, {
headers: { 'Content-Type': 'text/plain; charset=utf-8' },
})
}Inspect the generated robots.txt or start the production adapter. A local development route is not proof of the deployed response.
Open https://example.com/robots.txt; check the status, plain-text content type, host, and sitemap URL.
Make sure important pages are not disallowed. Keep rules limited to paths you intend crawlers to skip.
Open every sitemap URL listed and confirm it contains canonical, indexable URLs that return successfully.
When a deployment uses a path prefix or a non-root domain, verify that the robots file still lives at the crawler-facing origin root. If a CDN serves a cached copy, purge or wait for that cache after changing the rules, then request the public URL again.
For the related setup, see Astro XML sitemaps, robots.txt rules, and noindex directives.
3 questions people ask next, answered from the sources on this page.
For a static file, put it in the root public/ directory; Astro copies it to the deployed site root. Use a src/pages/robots.txt.ts endpoint when the content must be generated.
Add a Sitemap: line with the absolute URL of the sitemap or sitemap index your deployment serves. Astro’s sitemap integration documents a sitemap index; verify the exact output path for your configuration.
No. Robots rules control crawling. To keep a crawlable public page out of Google, serve a page-level noindex directive and allow Google to fetch the page.
Run the free audit, then approve the fixes. Every change can be undone.