question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add an example how to add robots.txt or sitemap.xml

See original GitHub issue

Edit by Maintainers

Root level files are supported in Next.js 9.1 and newer.

Create the robots.txt file in the public/ directory.

For example:

pages/index.js
public/robots.txt

Note the public folder is on the same level as the pages folder, not inside of it!

Read more in the docs: https://nextjs.org/docs/basic-features/static-file-serving


There’s a closed issue related to this without a clear answer: https://github.com/zeit/next.js/issues/226

It’s kind of closed in favor of the Programmatic API so I guess I should implement that with custom server?)

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:2
  • Comments:33 (12 by maintainers)

github_iconTop GitHub Comments

22reactions
spleshkacommented, Feb 13, 2020

Another way of doing this: put robots.txt into /static folder, then add this to your server config:

const options = {
  root: __dirname + '/static/',
  headers: {
    'Content-Type': 'text/plain;charset=UTF-8',
  }
};
server.get('/robots.txt', (req, res) => (
  res.status(200).sendFile('robots.txt', options)
));
14reactions
Timercommented, Jun 25, 2019

Next.js now has a public/ folder that mounts files at the root automatically! Create public/robots.txt and you’re done!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Add Your Sitemap To Your Robots.txt File
Step #1: Locate Your Sitemap URL · Step #2: Locate Your Robots.txt File · Step #3: Add Sitemap Location To Robots.txt File.
Read more >
How to Add Sitemaps to Robots.txt?
2.1 Login to Your WordPress Website ; 2.2 Navigate to Edit Robots.txt ; 2.3 Add Sitemap URL in Your Robots.txt ; 2.4 Save...
Read more >
How to Add Sitemap to Robots.txt (Full Guide)
Step 1: Determine Your Sitemap URL · Step 2: Locate Your Robots.txt File · Step 3: Add a Sitemap to the Robots.txt File....
Read more >
Create and submit a robots.txt file | Google Search Central
Learn how to create a robots.txt file, see examples, and explore robots.txt ... The site's sitemap file is located at https://www.example.com/sitemap.xml .
Read more >
Robots.txt sitemap: how to reference it?
It's a best practice to always reference your XML sitemap(s) in your robots.txt file. Here are the rules of engagement: ... On top...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found