# Astro robots.txt

> Serve robots.txt from Astro’s public directory or generate it from the configured site URL, then verify the deployed rules.

Canonical: https://scaplet.com/seo/astro/robots-txt

Guide Astro · Crawling

Serve robots.txt from Astro’s public directory or generate it from the configured site URL, then verify the deployed rules.

3 min

read

4

sources

Oct 24, 2026

updated

Scaplet Editorial Team

author

In one line

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.

30-second check

## Where does your site stand?

Four quick questions, then a straight answer.

1/4Have you checked your own site for this?

Summarize this page with [ChatGPT](https://chatgpt.com/?hints=search&q=Summarize%20https%3A%2F%2Fscaplet.com%2Fseo%2Fastro%2Frobots-txt%20(%22Astro%20robots.txt%22)%20in%205%20bullet%20points%2C%20then%20tell%20me%20the%20one%20thing%20I%20should%20do%20next.) [Claude](https://claude.ai/new?q=Summarize%20https%3A%2F%2Fscaplet.com%2Fseo%2Fastro%2Frobots-txt%20(%22Astro%20robots.txt%22)%20in%205%20bullet%20points%2C%20then%20tell%20me%20the%20one%20thing%20I%20should%20do%20next.) [Perplexity](https://www.perplexity.ai/search?q=Summarize%20https%3A%2F%2Fscaplet.com%2Fseo%2Fastro%2Frobots-txt%20(%22Astro%20robots.txt%22)%20in%205%20bullet%20points%2C%20then%20tell%20me%20the%20one%20thing%20I%20should%20do%20next.) [![Google](/logos/ai/google-color.svg)AI Mode](https://www.google.com/search?udm=50&q=Summarize%20https%3A%2F%2Fscaplet.com%2Fseo%2Fastro%2Frobots-txt%20(%22Astro%20robots.txt%22)%20in%205%20bullet%20points%2C%20then%20tell%20me%20the%20one%20thing%20I%20should%20do%20next.)

On this page

## 3 parts, 3 minutes.

1. [Choose static or generated output 01](#choose-static-or-generated-output)
2. [Generate the sitemap line from Astro config 02](#generate-the-sitemap-line-from-astro-config)
3. [Verify the deployed file 03](#verify-the-deployed-file)

_01_Which Astro setup fits?

## Choose static or generated output

Setup

### Static rules

Use

`public/robots.txt`

Check

Confirm the host publishes the file at `/robots.txt`

Setup

### Sitemap URL comes from config

Use

A `src/pages/robots.txt.ts` endpoint

Check

Set the site URL and return plain text

Setup

### Rules vary by request

Use

Server-rendered endpoint or deployment layer

Check

Confirm your adapter supports the runtime behavior

Astro'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.

public/robots.txt

```
User-agent: * Allow: / Sitemap: https://example.com/sitemap-index.xml
```

_02_Check it

## Generate the sitemap line from Astro config

Astro’s sitemap integration can create a [sitemap index](/glossary/xml-sitemap) for a site with multiple sitemap files. The configured `site` 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.

**Do not use robots.txt to hide a page**A `Disallow` rule can stop compliant crawlers fetching a URL, but Google says a blocked URL can still appear in [search results](/glossary/serp) without a description. For `noindex` to work, the page must not be blocked by [robots.txt](/glossary/robots-txt), or the crawler never sees the rule. Use a password for private content.

src/pages/robots.txt.ts

```
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' }, }) }
```

_03_How it works

## Verify the deployed file

1. 1

### Build the production output

Inspect the generated `robots.txt` or start the production adapter. A local development route is not proof of the deployed response.
2. 2

### Request the canonical host

Open `https://example.com/robots.txt`; check the status, plain-text content type, host, and sitemap URL.
3. 3

### Test important paths

Make sure important pages are not disallowed. Keep rules limited to paths you intend crawlers to skip.
4. 4

### Check sitemap consistency

Open every sitemap URL listed and confirm it contains canonical, [indexable](/glossary/indexability) 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](/seo/astro/xml-sitemap), [robots.txt rules](/glossary/robots-txt), and [noindex directives](/glossary/noindex).

Sources · 4

## Every fact, linked and dated.

Official docs first. The date is when we last opened each page.

- astro.build
- google.com

1. 01 [Project structure: public directory | Astro Docs](https://docs.astro.build/en/basics/project-structure/) docs.astro.build · checked 2026-10-24
2. 02 [@astrojs/sitemap | Astro Docs](https://docs.astro.build/en/guides/integrations-guide/sitemap/) docs.astro.build · checked 2026-10-24
3. 03 [Introduction to robots.txt | Google Search Central](https://developers.google.com/search/docs/crawling-indexing/robots/intro) developers.google.com · checked 2026-10-24
4. 04 [Block search indexing with noindex | Google Search Central](https://developers.google.com/search/docs/crawling-indexing/block-indexing) developers.google.com · checked 2026-10-24

Questions

## Asked a lot.

3 questions people ask next, answered from the sources on this page.

_01_ Where should robots.txt go in an Astro project?

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.

_02_ How do I add a sitemap to Astro robots.txt?

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.

_03_ Can robots.txt add noindex to an Astro page?

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.

## Keep learning

[All platform guides](/seo)

[Learn Astro SEO Frameworks](/seo/astro) [Related Noindex Crawling and indexing](/glossary/noindex) [Read next Next.js robots.txt Frameworks](/seo/nextjs/robots-txt) [Do Run a free site audit Free, about two minutes](/site-audit)

Nearby in platform guides
[BigCommerce SEO](/seo/bigcommerce)

More in Astro SEO
[Astro 404 page](/seo/astro/404) [Astro Google Analytics](/seo/astro/google-analytics) [Astro redirects](/seo/astro/redirects) [Astro robots.txt](/seo/astro/robots-txt) [Astro XML sitemap](/seo/astro/xml-sitemap)

Terms on this page
[XML sitemap](/glossary/xml-sitemap) [SERP](/glossary/serp) [robots.txt](/glossary/robots-txt) [Indexability](/glossary/indexability) [Noindex](/glossary/noindex)

Free · 2 minutes

## Tools point. Agencies advise. _This one ships._

Run the free audit, then approve the fixes. Every change can be undone.

[Audit my site free](/site-audit)

Free, no card 60 seconds Nobody will call you

- **46** fixes shipped without a ticket Brightpipe
- **0→7** ChatGPT citations in six weeks Paylane
