SEO · Technical SEO

XML Sitemaps

An XML sitemap lists the URLs you want indexed, helping search engines discover new and updated pages faster.

Intermediate 5 min Lesson 12 of 22
Before you start:robots.txt
0/22 in SEO
On this page · 5 min · Intermediate

Learning objectives#

  • Write a valid XML sitemap
  • Choose which URLs to include
  • Use lastmod correctly
  • Generate and submit sitemaps

Explanation#

A sitemap is an XML file of <url> entries with <loc> (full canonical URL) and optionally <lastmod> (last significant change).

Include only canonical, indexable, 200-status pages. Exclude redirects, noindex pages and duplicates.

Limits: 50,000 URLs or 50 MB per file; larger sites use a sitemap index file.

Generate it automatically at build time, reference it in robots.txt and submit it in Search Console.

Code example: A small sitemap#

Razor / Markupsitemap.xml Illustrative
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
  <url>
    <loc>https://techiebabaji.com/</loc>
    <lastmod>2026-10-29</lastmod>
  </url>
  <url>
    <loc>https://techiebabaji.com/tutorials/react/usestate-hook</loc>
    <lastmod>2026-10-27</lastmod>
  </url>
  <url>
    <loc>https://techiebabaji.com/tutorials/sql-server/inner-join</loc>
    <lastmod>2026-10-20</lastmod>
  </url>
</urlset>
Expected output
Search Console shows “Success” for the sitemap and the number of discovered URLs.

This example is illustrative. Copy or download it and run it in your own environment; the expected output is shown above.

Step-by-step explanation#

  1. The urlset uses the sitemaps.org namespace.
  2. Each loc is a full canonical URL.
  3. lastmod reflects real content updates.
  4. The file is linked from robots.txt.

Real-world use case#

This site’s build script generates sitemap.xml from every route, so new lessons are listed the moment they are deployed.

Common mistakes#

Listing redirected or noindex URLs

Mixed signals waste crawl effort. List only canonical, indexable URLs.

Setting lastmod to today for every page

Search engines learn to ignore it. Use the real change date.

Best practices#

  • Generate automatically
  • Only canonical 200 URLs
  • Accurate lastmod
  • Submit in Search Console

Remember this#

loc = full canonical URL.

Only indexable pages.

50,000 URLs per file, then an index.

Practice exercise#

Your task: Write a sitemap index referencing two sitemaps.

Show solution
Razor / Markup Illustrative
<?xml version="1.0" encoding="UTF-8"?>
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
  <sitemap><loc>https://example.com/sitemap-tutorials.xml</loc></sitemap>
  <sitemap><loc>https://example.com/sitemap-interview.xml</loc></sitemap>
</sitemapindex>

Mini quiz#

XML Sitemaps quizMultiple choice Question 1 of 1

Which URLs belong in a sitemap?

Score so far: 0/0

Want more? Practise all SEO MCQs · SEO interview questions

My notes#

Saved in this browser.

Progress is saved in this browser. Sign in to sync.