Blog

How to Create an XML Sitemap: Step-by-Step Technical Guide

by Madhavan A • Published: October 16, 2026
How to Create an XML Sitemap: Step-by-Step Technical Guide
Contents
Want a Quick Summary?

Summarize this article instantly with ChatGPT.

Summarize with AI

An XML sitemap is a structured blueprint of your website designed specifically for search engine crawlers like Googlebot and Bingbot. It catalogs all canonical, indexable URLs across your domain, providing search engines with metadata about when each page was last updated, how frequently it changes, and how it relates to other pages.

Without a clean sitemap, search engines must discover your content solely through internal links. On large catalogs, dynamic web apps, or newly launched websites with few backlinks, pages can easily remain undiscovered. Learning how to create an XML sitemap ensures search bots crawl your most profitable landing pages efficiently without wasting crawl budget on irrelevant URLs.

What Is an XML Sitemap and Why Does It Matter for SEO?

An XML (Extensible Markup Language) sitemap is a machine-readable document hosted on your server, usually accessible at yourdomain.com/sitemap.xml. Unlike HTML sitemaps designed to help human visitors navigate a website footer, an XML sitemap is created strictly for search engine parsers.

Submitting an XML sitemap provides four key search benefits:

  • Faster Content Discovery: When you publish fresh service pages or educational articles, search crawlers read your sitemap to locate new URLs immediately instead of waiting to stumble across an internal link.
  • Efficient Crawl Budget Usage: Directing bots only to high-value, indexable URLs prevents crawlers from spending finite resources processing search filter parameters, duplicate URLs, or utility pages.
  • Timely Update Signals: The <lastmod> tag informs search engines exactly when an existing page was revised, prompting recrawls when content is updated.
  • Support for Media Assets: Specialized sitemap extensions allow you to supply metadata for product images, embedded videos, and news articles to qualify for rich SERP features.

Understanding Standard XML Sitemap Tags and Syntax

A standard XML sitemap follows strict protocol guidelines defined by sitemaps.org. Here is a basic example containing a single URL entry:

<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
  <url>
    <loc>https://www.yourdomain.com/services/</loc>
    <lastmod>2026-10-15T09:30:00+00:00</lastmod>
    <changefreq>weekly</changefreq>
    <priority>0.8</priority>
  </url>
</urlset>

The core elements of an XML sitemap include:

  • <urlset> (Required): The opening and closing container tag that encapsulates the file and defines the XML schema protocol.
  • <url> (Required): The parent tag for each individual URL entry.
  • <loc> (Required): The absolute, canonical URL of the page. It must specify the exact protocol (HTTP or HTTPS) and match your domain configuration.
  • <lastmod> (Optional but Recommended): The date and time when the page was last updated, formatted in W3C Datetime format (YYYY-MM-DD). Google uses this tag to prioritize recrawling.
  • <changefreq> and <priority> (Optional): Historically used to suggest crawl frequency and relative importance. Modern search engines like Google largely ignore these two fields in favor of their own internal scheduling algorithms.

Sitemap Index Files: Managing Sites with More Than 50,000 URLs

The XML protocol limits a single sitemap file to a maximum of 50,000 URLs and an uncompressed file size of 50MB. If your website exceeds either threshold, you must split your URLs into multiple sitemaps and reference them inside a parent Sitemap Index File.

<?xml version="1.0" encoding="UTF-8"?>
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
  <sitemap>
    <loc>https://www.yourdomain.com/page-sitemap.xml</loc>
    <lastmod>2026-10-12</lastmod>
  </sitemap>
  <sitemap>
    <loc>https://www.yourdomain.com/product-sitemap.xml</loc>
    <lastmod>2026-10-14</lastmod>
  </sitemap>
</sitemapindex>

Method 1: Creating an XML Sitemap on WordPress

WordPress offers two primary ways to generate and maintain XML sitemaps:

Native WordPress Sitemaps

Since version 5.5, WordPress automatically generates a basic sitemap index at yourdomain.com/wp-sitemap.xml. While convenient, native WordPress sitemaps offer limited customization: you cannot easily exclude thin tags, remove specific utility pages, or modify the <lastmod> output without writing custom PHP hooks.

Using Dedicated SEO Plugins

Most site managers use established SEO plugins like Rank Math, Yoast SEO, or SEOPress to handle sitemaps dynamically:

  1. Install and activate your chosen SEO plugin from the WordPress repository.
  2. Navigate to the plugin's Sitemap Settings tab.
  3. Enable the XML Sitemap toggle. The plugin will create a clean dynamic index (typically at yourdomain.com/sitemap_index.xml).
  4. Configure post types: Include essential posts, pages, and custom product post types. Exclude low-value taxonomy archives such as post tags, author archives, and media attachment URLs.

Method 2: Generating Sitemaps on Shopify, Webflow, and Squarespace

Modern hosted website platforms handle XML sitemaps automatically out of the box:

  • Shopify: Generates a pre-configured sitemap index automatically at yourstore.com/sitemap.xml. It automatically clusters products, collections, blog posts, and pages into separate sub-sitemaps and updates whenever inventory changes.
  • Webflow: Navigate to Project Settings > SEO > Sitemap. Toggle "Auto-generate sitemap" to Yes. Webflow will dynamically update your sitemap whenever changes are published. You can also exclude specific utility pages by adding a custom noindex directive in page settings.
  • Squarespace: Creates a dynamic sitemap automatically at yourdomain.com/sitemap.xml. Any page hidden behind password protection or marked with a noindex directive is excluded automatically.

Method 3: Generating Sitemaps for Custom Sites and Single Page Apps

For custom web applications built with frameworks like Next.js, Nuxt, Laravel, or custom PHP, you can generate sitemaps programmatically or through crawling software:

Using Static Crawlers (Small to Mid-Sized Sites)

  1. Download and launch Screaming Frog SEO Spider.
  2. Enter your root domain and crawl all pages.
  3. In the top menu, click Sitemaps > XML Sitemap.
  4. Select the tags you wish to include (such as <lastmod> based on server headers) and exclude non-200 OK status codes.
  5. Export the generated sitemap.xml file and upload it directly to your server's root public directory (e.g., /public_html/).

Programmatic Generation (Next.js App Router)

In modern Next.js applications, you can create a dynamic sitemap.js or sitemap.ts file inside the app/ directory that fetches database routes and returns a valid XML schema at build or request time:

export default async function sitemap() {
  const baseUrl = 'https://www.yourdomain.com';
  
  // Example: Fetch dynamic blog slugs from an API or database
  const posts = await getBlogPosts();
  const postUrls = posts.map((post) => ({
    url: `${baseUrl}/blog/${post.slug}`,
    lastModified: post.updatedAt,
  }));

  return [
    { url: baseUrl, lastModified: new Date() },
    { url: `${baseUrl}/services`, lastModified: new Date() },
    ...postUrls,
  ];
}

What to Include vs. What to Exclude from an XML Sitemap

An XML sitemap should only contain URLs that you actively want indexed and ranked in search results. Mixing non-canonical or broken URLs into a sitemap sends contradictory signals to search bots.

Category Include in Sitemap? Reasoning
Primary Canonical Pages (200 OK) Yes Core landing pages, high-value service pages, and indexable articles.
Redirected URLs (301 / 302) No Wastes crawl budget; sitemaps should link only to final destination targets.
Broken URLs (404 / 410) No Communicates poor site maintenance and creates crawl errors.
Noindexed Pages (noindex) No Sending contradictory instructions (crawl via sitemap vs. do not index).
Parameterized / Filtered URLs No Faceted navigation variants cause severe index bloat.
Paginated Archives (/page/2/) Usually No Deep pagination rarely needs direct priority sitemap discovery.

How to Submit and Verify Your Sitemap

Once your XML sitemap is generated and accessible on your server, follow these steps to deliver it to search engines:

1. Submit to Google Search Console

  1. Log into your Google Search Console property.
  2. In the left sidebar under Indexing, click Sitemaps.
  3. Under "Add a new sitemap", enter your sitemap filename or relative path (e.g., sitemap_index.xml).
  4. Click Submit. Google will queue the file and display a green "Success" status once parsed.

2. Submit to Bing Webmaster Tools

  1. Log into Bing Webmaster Tools.
  2. In the left menu, select Sitemaps.
  3. Click the Submit sitemap button in the upper right.
  4. Enter the complete URL of your sitemap (e.g., https://www.yourdomain.com/sitemap.xml) and click Submit.

3. Declare the Sitemap in Robots.txt

Search engines automatically read your robots.txt file when visiting your domain. Add an explicit directive pointing directly to your sitemap URL at the bottom of the file:

User-agent: *
Disallow: /admin/
Disallow: /checkout/

Sitemap: https://www.yourdomain.com/sitemap_index.xml

Common XML Sitemap Mistakes to Avoid

Even small syntax or architectural oversights can prevent search engines from processing your sitemap correctly:

  • Using Relative URLs: Every URL inside the <loc> element must be an absolute URL (e.g., https://www.yourdomain.com/page/, never /page/).
  • Inconsistent Protocol or Subdomain: If your site enforces HTTPS and non-www, do not list HTTP or www URLs in your sitemap. Every URL should match your canonical sitewide format.
  • Failing to Update <lastmod> Accurately: Updating the <lastmod> tag on every URL daily without making actual content changes causes search engines to mistrust and ignore your timestamps. Only update this tag when page copy, headers, or resources have materially changed.
  • Exceeding File Size Limits: Keep individual sitemap files under 50,000 URLs and 50MB. Split large files into a sitemap index structure.

Automated Plugins vs. Strategic Technical Architecture

While CMS plugins can automatically output basic XML files, managing sitemaps across complex corporate ecosystems requires careful technical alignment. In multi-regional platforms, enterprise e-commerce portals with faceted filtering, and headless web applications, improper sitemap rules can cause index bloat and misallocated crawl capacity.

For organizations operating in competitive commercial markets looking to build an airtight technical foundation, partnering with a dedicated SEO services company in Dubai ensures your XML sitemaps, robots directives, canonical architecture, and on-page optimization work together to achieve maximum search visibility.

Keep Your Sitemap Clean and Current

Creating an XML sitemap is a core component of technical SEO. By ensuring your sitemap contains only 200 OK canonical pages, updating lastmod timestamps accurately, declaring the file in robots.txt, and reviewing Google Search Console submission reports regularly, you give search engines a direct path to index and rank your revenue-driving content.

Performance Driven

Looking for Measurable Business Growth?

Partner with BrandStory for end-to-end digital & creative excellence.

Talk to Our Experts
Data-driven ROI solutions
Madhavan A

Madhavan A

Madhavan A is a digital marketing expert with a strong SEO specialisation, bringing 8+ years of hands-on experience in driving organic growth and search visibility. He focuses on building data-driven strategies, optimising content performance, and delivering measurable results across competitive digital landscapes.

Transform Your Digital Growth with BrandStory

From SEO, PPC, social media marketing, and content marketing to website development, branding, and lead generation, BrandStory delivers result-driven digital marketing services in Dubai and across the UAE, helping businesses attract, engage, and convert more customers.

Trusted by 1000+ leading brands in Dubai and globally including:

Client Logo
Client Logo
Client Logo
Client Logo

Related Blogs

How to Fix Mobile Usability Issues: Step-by-Step Technical Guide
October 16, 2026
How to Fix Mobile Usability Issues: Step-by-Step Technical Guide

With Google operating entirely on mobile-first indexing, search engine crawlers assess, index, and rank web pages base...

How to Fix JavaScript SEO Issues: Complete Technical Guide
October 16, 2026
How to Fix JavaScript SEO Issues: Complete Technical Guide

Modern web development relies heavily on JavaScript frameworks like React, Next.js, Vue, Angular, and Nuxt to build ri...

How to Fix Soft 404 Errors: Complete Technical SEO Guide
October 16, 2026
How to Fix Soft 404 Errors: Complete Technical SEO Guide

A Soft 404 error occurs when a web server responds with an HTTP 200 OK status code signaling success, but search engin...

How to Set Up Hreflang Tags: Technical SEO Implementation Guide
October 16, 2026
How to Set Up Hreflang Tags: Technical SEO Implementation Guide

The hreflang attribute is an HTML specification that informs search engines about the language and geographical target...

How to Fix Mixed Content Errors: Complete Security Guide
October 16, 2026
How to Fix Mixed Content Errors: Complete Security Guide

A mixed content error occurs when an initial webpage loads securely over HTTPS, but subresources such as images, scrip...

How to Fix Missing Meta Descriptions: Complete SEO Guide
October 16, 2026
How to Fix Missing Meta Descriptions: Complete SEO Guide

A missing meta description occurs when an HTML document lacks a &lt;meta name="description"&gt; tag in its &lt;head&gt...