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.
Related Guides and Next Steps
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.
What is technical SEO? — A related Technical SEO guide.
Technical SEO audit checklist — a related Technical SEO guide.
Crawl budget and indexation issues — a related Technical SEO guide.
JavaScript SEO for modern websites — a related Technical SEO guide.
Technical SEO Services if you want this work applied to your own site.
Ecommerce shopify SEO Services if you want this work applied to your own site.
Get a free SEO audit if you want a focused review of your pages.
FAQ
Robots.txt should allow the public pages and assets you care about, and the sitemap should list only the canonical, indexable URLs among those pages.
No. It helps discovery.
Indexation still depends on quality, canonical signals, robots tags and whether the page is unique enough to store.
Only as part of a wider URL policy. If you need to noindex those URLs, they must remain crawlable so the tag can be read.
Serve it over HTTPS at a stable URL, list that URL in robots.txt, and submit the same URL in Search Console.
Yes. Use a sitemap index that points to split files by section.
This is the standard approach on large sites.
Restore the previous robots.txt, fetch the file to confirm the change, and use URL Inspection on key pages. Ask for recrawls once the file is safe.
No. The sitemap should be a list of pages you want stored.
Noindexed URLs belong out of it.
No. An HTML sitemap is a page for people and internal links.
An XML sitemap is a machine list for crawlers. You can have both, but they are not interchangeable.
Include it when you can update it honestly. A fake daily lastmod on every URL is worse than omitting the field.
It is still useful, because you can point to the sitemap and avoid a guess about a missing file. A short Allow-all file is fine.
It is a weak control. Password-protect staging, noindex it, and keep it off the public host.
Robots.txt alone will not reliably hide it.

