Step 7 of 8

Create an XML sitemap

An XML sitemap shows search engines like Google and Bing where to find all the pages on your website.

About 15 minutes Updated 1 November 2026By Ian F. Cliffen

What is a sitemap?

A sitemap is a file, usually in the root folder of your site, that lists the pages (and optionally images and videos) you want search engines to find. Search engines read it to crawl your site more intelligently — especially new pages, and pages that few other pages link to.

The sitemap for this site is at https://thewebtoolbox.com/sitemap.xml. You’ll find a link to it at the bottom of every page.

What does an XML sitemap look like?

Here are the first few entries from this site’s sitemap:

sitemap.xml
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
  <url>
    <loc>https://thewebtoolbox.com/</loc>
    <lastmod>2026-11-01</lastmod>
  </url>
  <url>
    <loc>https://thewebtoolbox.com/register/register</loc>
    <lastmod>2026-11-01</lastmod>
  </url>
  <url>
    <loc>https://thewebtoolbox.com/register/domain-setup</loc>
    <lastmod>2026-11-01</lastmod>
  </url>
</urlset>

Each page gets a <url> entry with its full address in <loc>, and ideally the date it last changed in <lastmod>. You may see older sitemaps with <changefreq> and <priority> too; Google has said it ignores both, so don’t spend time on them.

The rules

  • Use full addresses, including https://, exactly as they appear in your browser (same www choice, same ending).
  • List only pages you want in search results: no login pages, thank-you pages, duplicates or pages that redirect.
  • Only change <lastmod> when the page content really changes. Search engines learn to ignore dates that are always “today”.
  • Up to 50,000 addresses and 50 MB per file. Bigger sites split into several sitemaps listed in a sitemap index.
  • Save as UTF-8, and escape & in addresses as &amp;.

Three ways to make one

1. By hand

For a site of a dozen pages, copy the example above into a plain-text file called sitemap.xml, change the addresses and upload it to your root folder. Remember to update it when you add a page.

2. With a free generator

Online generators crawl your site and build the file for you; most are free for sites under 500 pages. Screaming Frog’s SEO Spider is a program you download and run on your own computer, and it’s also excellent for finding broken links.

If you use WordPress, it makes a basic sitemap automatically at /wp-sitemap.xml, and SEO plugins can replace it with a fuller one.

3. Automatically, with PHP

This is how our sites do it. A small PHP file builds the sitemap fresh each time it’s asked for, so it’s never out of date. Save this as sitemap.php:

sitemap.php
<?php
// sitemap.php — lists every page and the date its file last changed
header('Content-Type: application/xml; charset=UTF-8');

$site  = 'https://www.your-domain.com';
$pages = ['/' => 'index.php', '/about' => 'about.php', '/contact' => 'contact.php'];

echo '<?xml version="1.0" encoding="UTF-8"?>', "\n";
echo '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">', "\n";
foreach ($pages as $path => $file) {
    $date = date('Y-m-d', filemtime(__DIR__ . '/' . $file));
    echo "  <url><loc>{$site}{$path}</loc><lastmod>{$date}</lastmod></url>\n";
}
echo "</urlset>\n";

Then add one line to your .htaccess file so the usual address, /sitemap.xml, runs it:

.htaccess
RewriteEngine On
RewriteRule ^sitemap\.xml$ sitemap.php [L]

A database-driven site can loop through its products, articles or listings in the same way.

Tell search engines where it is

Add the address to your robots.txt file (next step), and submit it in Google Search Console and Bing Webmaster Tools. Search Console will then show how many of its addresses Google has found, and any problems.

Ready to build? Every guide on this site was written and tested on OnPoint Hosts — UK cPanel hosting with free SSL and a free first-year domain, from £4.25 a month.

Get hosting