llms.txt for Next.js
A file in public/ is served at the site root; nothing else is needed unless middleware or i18n rewrites get in the way.
Where the file lives
- Put the file at public/llms.txt in the project root (next to package.json). Next serves everything in public/ at the root URL, so it appears at https://your-domain/llms.txt.
- Alternative for a file that changes with your content: an App Router route handler at app/llms.txt/route.ts that returns the text with a text/plain content type. Use one approach, not both: a public file and a route with the same path conflict.
- Deploy. On a self-hosted `next start`, the list of public files is read when the server starts, so a file added after boot returns 404 until the process restarts.
Serving it as text
- Files in public/ get their content type from the extension: .txt is served as text/plain. No headers configuration is needed.
- With `output: 'export'` the file is copied into out/ and served by whatever host serves that folder.
The Next.js pitfall: Middleware and locale prefixes
If the project has proxy.ts or middleware.ts that redirects or rewrites root paths (locale prefixes such as /en/…, auth redirects, trailing-slash rules), /llms.txt can be redirected to /en/llms.txt or to a login page. Exclude it in the matcher, for example `matcher: ['/((?!llms\\.txt|robots\\.txt|sitemap\\.xml|_next|api).*)']`.
A redirect to an HTML page is what the validator reports as E5 (HTML served instead of the file).
Check it
Request https://your-domain/llms.txt and check the response is 200 with content-type text/plain and no redirect.
What goes in the file, section by section, is in the knowledge base. The validator checks 14 rules and shows every deduction.