Technical SEO

Xml Sitemaps and Robots.txt, Done Properly

Xml Sitemaps and Robots.txt are two small files that decide what crawlers are invited to fetch and what they are asked not to request. Used together, they keep discovery clear.

Used carelessly, they fight each other.

Featured graphic for the xml sitemaps guide by Muhammad Zeeshan
Get a free SEO auditConnect on LinkedInBook a call
Short answer: Xml Sitemaps should list only canonical, indexable URLs that return a 200 status. Robots.txt should block paths you do not want crawled, without blocking the files Google needs to render a page, and it should point to the sitemap.

What Each File Is for

Robots.txt is fetched first and tells a crawler which paths it may request.

It does not remove a URL from the index by itself, and a blocked URL can still appear in results if other sites link to it, often without a snippet.

An XML sitemap is a list of URLs you consider worth discovering. It does not force indexation, and it cannot override a noindex tag, a canonical that points elsewhere, or a robots block.

Think of robots.txt as a gate and the sitemap as a guest list. The guest list should never include people the gate is told to turn away.

Writing a Safe Robots.txt

Keep the file short and specific. Block admin paths, internal search results, cart and checkout flows, and other sections that should not be crawled, and leave public templates allowed.

Do not block CSS, JavaScript, image or font paths that the public templates need. A crawler that cannot render the page may store a weaker version of it.

Use one set of rules for the production host and keep staging on a different host with its own stricter rules. Copying a staging Disallow-all file to production is a classic outage.

Add a Sitemap line with the absolute URL of your sitemap index. That reference is a reliable discovery hint and helps crawlers that do not rely only on Search Console.

Xml Sitemaps and Robots.txt Working Together

The sitemap should include only the URLs you want indexed: canonical, public, 200-status pages with a useful purpose. Redirected, noindexed, canonicalised and parameter URLs do not belong there.

If robots.txt blocks a path, remove those URLs from the sitemap. Listing a blocked URL asks a crawler to notice a page it is not allowed to fetch, which wastes time and creates confusion in reports.

Large sites should split sitemaps by type, such as services, locations, articles and products, and wrap them in a sitemap index. Split files make errors easier to find when one section fails.

  • One canonical URL per page in the sitemap.

  • Lastmod dates that reflect real updates, not a daily rewrite of every row.

  • A sitemap index when you pass the practical size of a single file.

  • A robots.txt Sitemap line that matches the file you submit in Search Console.

How to Build and Maintain the Sitemap

Generate the list from the same source that powers your canonical URLs, not from a leftover crawl of the site. If the CMS has a canonical field, the sitemap should follow it.

Update lastmod when the meaningful content changes, not when a sidebar or a global timestamp changes. Fake freshness in a sitemap teaches crawlers to ignore your dates.

Submit the sitemap in Google Search Console and check the processing reports. Errors about unsupported formats, invalid URLs or unavailable files should be treated as release blockers.

When you retire a page, remove it from the sitemap and send users and crawlers to the right successor with a redirect, or let it 404 or 410 if there is no successor.

Common Conflicts Between the Two Files

A frequent conflict is a sitemap that lists URLs the robots file blocks. Another is a robots file that blocks a sitemap path itself, so the guest list cannot be read.

Teams also add noindex to a template and leave the URLs in the sitemap. The sitemap then keeps suggesting pages that the HTML asks Google not to store.

Wildcard Disallow rules are easy to get wrong. Test any new rule against sample URLs for articles, products, filters, pagination and assets before you ship it.

Images, Video, Hreflang and Other Extensions

Image and video sitemap extensions can help when important media is hard to discover, such as product photos loaded late. They are optional for simple article sites.

Hreflang should be defined in a consistent way, either in the HTML or in the sitemap, and every language URL should agree. Do not list only one language in the sitemap of a multi-market site.

International URL questions beyond the sitemap are covered in International SEO for Multi-Market Sites.

How to Test a Change Before It Spreads

After any robots or sitemap change, fetch the files as a crawler would, then inspect a few allowed and blocked URLs. Confirm that public pages still render with their assets.

In Search Console, watch the robots.txt report and the sitemap report for several days. A sudden drop in discovered URLs often points to a new Disallow or a sitemap that failed to process.

Keep a copy of the previous robots.txt in version control. This is one of the few SEO files where a typo can hide a whole section in a single deploy.

When These Files Are Not Enough

Robots.txt cannot cleanly remove a URL that is already indexed and widely linked. Allow the URL, add a noindex, and wait for a recrawl, or redirect it if it has a successor.

A sitemap cannot repair a site with no internal links. Deep pages still need a path from navigable pages, or they will be found slowly even when listed.

Parameter and facet rules belong in the templates and the server, not only in these two files. Use the files to describe a URL policy you have already enforced.

A Worked Example After a CMS Migration

A CMS move generates a new sitemap that still contains old slugs, HTTP URLs and a handful of staging paths. Search Console starts reporting invalid URLs, and a few staging pages appear in a site: search.

The team rebuilds the sitemap from the canonical field in the new CMS, removes every non-200 URL, and adds a robots.txt Sitemap line that points only at the new index.

Staging is moved behind authentication and given its own robots file, so it can no longer be discovered through a leftover link in the public sitemap.

Within a crawl cycle the invalid-URL report shrinks, and the public sitemap count matches the number of real service, article and location pages.

File Size, Encoding and Freshness Details

Keep each sitemap in a supported format, encoded in UTF-8, and within the documented URL and file-size limits. When you approach those limits, split by section instead of trimming useful URLs at random.

Use absolute HTTPS URLs, not relative paths. Relative rows are a common generator bug and can be rejected or resolved to the wrong host.

If your generator rewrites the whole file on every build, that is fine, but lastmod should still change only when the page changed. A global rebuild date is not a content update.

Serve the file with a reasonable cache lifetime so crawlers do not keep an obsolete list, but do not block them with a long stale cache after a migration.

Governance for Teams That Ship Often

Put robots.txt and the sitemap generator in version control and review changes like any other production file. A typo in a Disallow rule is a production incident.

Add a simple test that fails the build if the sitemap lists a URL that is blocked, redirected or noindexed. Catching that in CI is cheaper than catching it in Search Console.

Name an owner for each file. When nobody owns robots.txt, a plugin or a theme update will eventually rewrite it.

Tell support and content teams where the files live, so a well-meant manual edit in a plugin screen does not fight the generator.

This guide belongs in a cluster of related pages, so you can go deeper without mixing intents on one URL. Use the links below to continue, or browse the full SEO blog.

Each of these pages has a different primary topic, which keeps the site from competing with itself.

FAQ

Find Out What Is Holding Your Rankings Back

Send your site for a free, focused SEO review.

Chat on WhatsApp