Sub topic 12
Publishing an XML sitemap
This chapter covers the last item in the plan: a file that tells search engines which pages your site has. It assumes you have finished the planning sitemap, chosen clean URL slugs, and can read basic XML and edit files on a web server or in a site builder.
Two things called a sitemap
The word "sitemap" covers two different artifacts. Mixing them up is the most common mistake in this area.
| Row | Planning sitemap | XML sitemap |
|---|---|---|
| Audience | Your team, designers, developers | Search engine crawlers |
| Format | Diagram or outline | XML file |
| Purpose | Decide structure and hierarchy | List the URLs you want indexed |
| Created | Before design | After the site is built |
| Contains | Sections, groupings, page names | Canonical URLs and optional metadata |
The planning sitemap shapes the site. The XML sitemap is derived from the finished site, and its URLs come from the slugs you chose earlier. This is why naming URLs comes before this step in the plan: the XML file can only be as consistent as the URLs it lists.
An XML sitemap does not change how your site looks or how visitors navigate. It also does not guarantee that a page will be indexed or ranked. It is a hint that helps crawlers discover pages and learn which URL you consider the main one.
What the file looks like
A minimal XML sitemap for a small business site looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<url>
<loc>https://www.example.com/</loc>
</url>
<url>
<loc>https://www.example.com/services/</loc>
</url>
<url>
<loc>https://www.example.com/contact/</loc>
</url>
</urlset>The parts are:
- The
<?xml ...?>line declares the XML version and the character encoding. Use UTF-8. <urlset>is the root element. Itsxmlnsattribute names the sitemap protocol and must be present exactly as shown.- Each
<url>element describes one page. <loc>holds the full, absolute URL of the page. It is the only required child of<url>.
Which URLs belong in the file
The rule is simple. List the canonical, indexable pages that you want people to find in search results. For the planning sitemap in this tutorial, that means every page in the hierarchy: Home, Services, Web design, Maintenance, Portfolio, About, and Contact.
Leave these out:
- Pages that redirect to another URL. List the destination instead.
- Pages that return an error, such as 404 or 500.
- Pages marked
noindex. Listing a page you also tell crawlers not to index sends a contradictory signal. - Duplicate versions of a page, such as the same page with tracking parameters or a different capitalization.
- Utility pages with no search value, such as a thank-you page after a form submission, login screens, and internal search results.
Use one canonical form
Pick one form of every URL and use it everywhere: in the sitemap, in internal links, and in redirects. Decide these four points once:
- Protocol:
https://, nothttp://. - Host:
www.example.comorexample.com, not both. - Trailing slash:
/services/or/services, not both. - Case: lowercase slugs only.
The example above uses https://www.example.com/services/. If your server actually answers at https://example.com/services, a crawler will see the sitemap URL redirect and may treat the entries as lower quality. Test each form in a browser before you commit to it.
Optional fields
The protocol defines a few optional elements besides <loc>:
<url>
<loc>https://www.example.com/services/web-design/</loc>
<lastmod>2026-11-20</lastmod>
</url><lastmod>is the date the page content last changed meaningfully, in W3C date format (YYYY-MM-DDor a full timestamp). Only include it if you can keep it accurate. If every page shows today's date on every build, crawlers learn to ignore the field.<changefreq>and<priority>exist in the protocol, but Google has said it ignores them. For a small site you can omit both.
A small site gains little from optional fields. An accurate list of <loc> entries matters more than extra metadata.
Size limits and larger sites
A single sitemap file may hold at most 50,000 URLs and be at most 50 MB uncompressed. A small business site is nowhere near either limit. If a site grows past them, you split the list into several files and add a sitemap index file that points to each one. You can ignore this until you need it.
Publishing the file
Follow these steps once the site is live.
- Generate the file. Most site builders, content management systems, and static site generators produce one automatically or through a plugin. Check that the output matches the pages in your planning sitemap. If the site is tiny, writing the file by hand is fine.
- Place it at the site root, conventionally
https://www.example.com/sitemap.xml. A sitemap can only list URLs at or below its own directory, so the root location lets it cover the whole site. - Confirm that it loads in a browser and returns status 200.
- Reference it in
robots.txtso any crawler can find it. - Submit it in the search engine's webmaster tool, such as Google Search Console or Bing Webmaster Tools.
The robots.txt reference is one line in a plain text file at https://www.example.com/robots.txt:
User-agent: *
Allow: /
Sitemap: https://www.example.com/sitemap.xmlThe Sitemap: line must use a full absolute URL. It is independent of the User-agent rules and can appear anywhere in the file.
Checking the result
A quick check catches most problems before a search engine does.
- Open the sitemap URL and confirm the XML is well formed. A missing closing tag makes the whole file unreadable.
- Compare the list with your planning sitemap. Every page in the plan should appear, and nothing should appear that is not in the plan.
- Request a few listed URLs and confirm each returns 200 with no redirect.
- After submitting, open the sitemap report in the webmaster tool. It shows how many URLs were discovered and lists parse errors.
You can also script a basic status check. This Python example reads a sitemap and reports the HTTP status of every URL, using only the standard library:
import sys
import urllib.error
import urllib.request
import xml.etree.ElementTree as ET
NS = {"sm": "http://www.sitemaps.org/schemas/sitemap/0.9"}
def fetch_status(url):
request = urllib.request.Request(url, method="HEAD")
try:
with urllib.request.urlopen(request, timeout=10) as response:
return response.status, response.geturl()
except urllib.error.HTTPError as error:
return error.code, url
def main(sitemap_url):
with urllib.request.urlopen(sitemap_url, timeout=10) as response:
root = ET.fromstring(response.read())
for loc in root.findall("sm:url/sm:loc", NS):
url = loc.text.strip()
status, final_url = fetch_status(url)
note = "" if final_url == url else f" (redirected to {final_url})"
print(f"{status} {url}{note}")
if __name__ == "__main__":
main(sys.argv[1])Run it with python check_sitemap.py https://www.example.com/sitemap.xml. Any line that does not start with 200, or that shows a redirect, points to an entry to fix. Python follows redirects automatically, which is why the script compares the final URL with the listed one.
Keeping it current
The file only helps while it matches the site. Update it whenever you add, remove, or move a page. Prefer automatic generation so that a new page appears in the sitemap without manual work. When you retire a page, remove it from the sitemap and redirect the old URL to the closest replacement.
Treat the sitemap as part of the plan's maintenance. When the planning sitemap changes, for example when you add a new service page, the XML sitemap changes too.
Common errors
- Listing
http://URLs on anhttps://site. - Mixing trailing-slash and non-slash forms.
- Including redirected, 404, or
noindexpages. - Setting
<lastmod>to the build time for every page. - Using relative URLs such as
/services/in<loc>. Each must be absolute. - Forgetting to escape special characters. An ampersand in a URL must be written
&in XML. - Leaving a staging-site hostname in the file after launch.
Where this fits in the plan
The planning work in earlier chapters feeds this step directly. Clear hierarchy gives you a complete page list, and consistent slugs give you clean URLs for <loc>.
Exercise
Your site's planning sitemap has seven pages. The XML sitemap you generated lists eight URLs: the seven pages plus /thank-you/, the page shown after a contact form is submitted. Another entry uses http://www.example.com/about/, but the site redirects all HTTP traffic to HTTPS. What should you change, and why?
Show answer
Remove /thank-you/, because it is a utility page with no search value and is not part of the planned hierarchy. Change the About entry to https://www.example.com/about/, because the sitemap should list the final canonical URL, not one that redirects. The result is seven entries that match the planning sitemap, each returning 200 without a redirect.
Exercise
You add a Sitemap: line to robots.txt, but the file also contains Disallow: /services/. What problem does this create, and how do you fix it?
Show answer
The sitemap lists /services/ and its child pages, while robots.txt tells crawlers not to fetch them. The signals contradict each other, and the pages may not be crawled. Remove the Disallow rule if the section should appear in search, or remove those URLs from the sitemap if it should not.