Performance: Robots.txt configuration
This affects how search engines crawl and index your site, indirectly impacting SEO and server load during crawling.
User-agent: * Disallow: /api/ Disallow: /admin/ Allow: /
User-agent: * Disallow:
| Pattern | Server Requests | Crawl Efficiency | User Impact | Verdict |
|---|---|---|---|---|
| Allow all paths | High (all pages crawled) | Low (wastes crawl budget) | Potential slowdowns under load | [X] Bad |
| Block heavy paths | Lower (fewer pages crawled) | High (focus on important pages) | Better server responsiveness | [OK] Good |
robots.txt file in a Next.js project?robots.txt file is used to communicate with search engines about which parts of the website they can access.robots.txt file using an API route in Next.js?robots.txt file must be served as plain text, so the header should be text/plain.robots.txt:
export default function handler(req, res) {
res.setHeader('Content-Type', 'text/plain');
res.send(`User-agent: *\nDisallow: /admin\nAllow: /public`);
}
What will search engines do when they read this robots.txt?User-agent: * (all bots), Disallow: /admin (block /admin), and Allow: /public (allow /public).robots.txt:
export default function handler(req, res) {
res.setHeader('Content-Type', 'text/plain')
res.send('User-agent: *\nDisallow: /secret')
}
But when you visit /api/robots.txt, the browser downloads a file instead of showing text. What is the likely cause?robots.txt content served via API route achieves this correctly?Allow: /$ which matches exactly the root URL, not all paths starting with '/'./blog/ lets crawlers access all pages under /blog.Pass the test and this pattern moves unknown