How to add robots.txt file in Next.js?

Anna Coding
Anna Coding
Published in
1 min readJan 15, 2020

In Next.js Version 9+, you can add robots.txt file in public folder under root. Everything inside the public folder will be exposed in the root domain level. Here, we assume you have static robots.txt file.

https://annacoding.com/robots.txt🔗

But if you put it in static folder, robots.txt file will be exposed as

https://annacoding.com/static/robots.txt

This is not what we want.

If you are not familiar with robots.txt, please check:

What is a robots.txt file? 🔗

Robots.txt is a text file webmasters create to instruct web robots (typically search engine robots) how to crawl pages on their website.

--

--

Anna Coding
Anna Coding

Free web, mobile, DevOps, cloud tutorials, issues & solutions. www.annacoding.com