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:
<?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&.
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:
<?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:
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.
Check it worked
Open it in your browser. Visit
yourdomain.co.uk/sitemap.xml. You should see your list of addresses. An error message or a blank page means the file has a mistake in it, or isn’t in your root folder.Submit it in Search Console. Open Sitemaps, type
sitemap.xmland select Submit.Check the status. After a day or two it should say Success, with a count of the pages it found. Select the sitemap, then See page indexing, to see which of those pages are in Google.
For a quick check of the code itself, paste the address into a free sitemap validator, or open the file in your code editor, which will highlight a missing </url>.
Common sitemap mistakes
- The wrong version of your addresses.
http://instead ofhttps://, orwww.when your site doesn’t use it, means every address redirects. Copy them from your browser’s address bar. - Listing pages you’ve hidden. A page with a
noindextag, or one blocked in robots.txt, sends Google mixed messages. Leave it out. - Old pages left in. Deleted or moved pages show up in Search Console as “Not found (404)” or “Page with redirect”. Take them out when you remove the page.
- Every date set to today. If every
<lastmod>is always today, search engines stop trusting it. See the catch with file dates above. - Forgetting to submit it. Search engines may find it in time, but listing it in robots.txt and Search Console means they find it straight away.
- Extra spaces before
<?xml. Even one blank line before the first line breaks the file. Insitemap.php, make sure nothing comes before<?php.
Questions about sitemaps
Do I need a sitemap for a small website?
Not strictly. Google can find the pages of a small, well-linked site on its own. A sitemap still helps a new site get found sooner, and Search Console uses it to show you which of your pages are indexed, so it is worth the ten minutes.
Where should my sitemap go?
In your root folder (public_html), so its address is yourdomain/sitemap.xml. A sitemap can only list pages in its own folder and the folders below it.
How often should I update my sitemap?
Whenever you add, remove or properly change a page. A sitemap built automatically with PHP or by WordPress updates itself.
Will a sitemap get my pages ranked higher?
No. A sitemap helps search engines find your pages; it does not make them rank better. Rankings depend on how useful the page is and how well it answers the search.
What is the difference between an XML sitemap and an HTML sitemap?
An XML sitemap is a file written for search engines. An HTML sitemap is an ordinary page listing your pages for visitors. You only need the XML one, though a clear menu and footer links help visitors and search engines alike.
What does “Couldn’t fetch” mean in Search Console?
Google could not download the sitemap. Open its address in your browser: check that it loads, is not blocked in robots.txt, and that the address you submitted is spelled exactly right. A brand-new submission sometimes shows this for a short while before it updates.