Hrishikesh Pathak

Create a basic sitemap for Nextjs website

Create a basic sitemap for Nextjs website

Hi developers, this is a short article on creating a basic sitemap for Nextjs website. The sitemap we are building in this article will be very basic and if you are just starting up, I think this will help you to save time and reduce complexity.

Basic xml sitemap structure

Generally we use xml sitemap and there is a basic structure of these kinds of sitemaps. You can know more about this in the official website.

So the basic structure of a sitemap is like this.

1<?xml version="1.0" encoding="UTF-8"?>
3<urlset xmlns="">
5 <url>
7 <loc></loc>
9 <lastmod>2005-01-01</lastmod>
11 <changefreq>monthly</changefreq>
13 <priority>0.8</priority>
15 </url>

Here the <lastmod>, <changefreq> and <priority> is optional. If you submit this sitemap in Google Search Console, then these tags are not important and ignored by the Googlebot.

Keep in mind that all the links in a sitemap should have the same host. If your site is, then all the links under <loc> should start with

Create our own sitemap

For this example, we take this site as an example. The complete URL of this website is

Let's assume we have 2 articles published in this website. The link of these articles are

So our sitemap will look like

1<?xml version="1.0" encoding="UTF-8"?>
2<urlset xmlns="">
3 <url>
4 <loc></loc>
5 </url>
6 <url>
7 <loc></loc>
8 </url>
9 <url>
10 <loc></loc>
11 </url>

Here you can see I have added the two article links along with the homepage link in this sitemap. Then name your sitemap file as sitemap.txt.

If you are using Nextjs then put this sitemap.xml file in your /public directory of your project. You can also add a robots.txt file in the same directory for better SEO. robots.txt of this site looks like

1User-agent: *

If you are a beginner, I prefer to use this configuration. You want to learn more about sitemap, then follow official google SEO blog.

If you like this article, please share, and you can follow me on Twitter. Have a good day.