Two small text files sit quietly at the root of most websites and shape how search engines interact with them: the XML sitemap and robots.txt. Neither is complicated, but a mistake in either one can hide important pages from Google or waste the time crawlers spend on your site.
Here's what each file does, how they work together, and how to check that yours are set up correctly.
How search engines find your pages
Before a page can rank, a search engine has to crawl it (fetch and read it) and then index it (store it so it can appear in results). Crawlers discover pages mainly by following links from pages they already know about.
Sitemaps and robots.txt both help guide that process:
- An XML sitemap says, "Here are the pages I'd like you to know about."
- A robots.txt file says, "Here's where you may and may not crawl."
What is an XML sitemap?
An XML sitemap is a file that lists the URLs on your site that you want search engines to discover. It can also include extra details, such as when each page was last modified.
A very simple sitemap 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>
<lastmod>2026-01-15</lastmod>
</url>
<url>
<loc>https://www.example.com/services/</loc>
</url>
</urlset>
Larger sites often use a sitemap index, which is a sitemap that points to several smaller sitemaps (for example, one for posts, one for pages and one for products). A single sitemap file can contain up to 50,000 URLs and must stay under 50 MB uncompressed.
Do you need a sitemap?
Google says sitemaps are most helpful for sites that are large, new with few external links, or have pages that aren't well linked internally. A small, well-linked site may be found without one, but there's no downside to having a sitemap, and most platforms create one automatically.
Where to find your sitemap
- WordPress: WordPress includes a basic sitemap at
/wp-sitemap.xml. SEO plugins like Yoast SEO or Rank Math replace it with their own, usually at/sitemap_index.xml. - Shop platforms and site builders: Most generate one at
/sitemap.xml. - Custom sites: You may need a generator tool, a script or a build plugin.
Try visiting yourdomain.com/sitemap.xml or yourdomain.com/sitemap_index.xml in your browser to see what you have.
What belongs in a sitemap
Include only pages you actually want to appear in search:
- Canonical versions of pages (one URL per piece of content)
- Pages that return a 200 OK status
- Pages that are indexable (no
noindextag)
Leave out redirects, error pages, duplicates, thank-you pages, internal search results and admin areas. A clean sitemap sends a clear signal about what matters.
What is robots.txt?
robots.txt is a plain text file at the root of your domain, such as https://www.example.com/robots.txt. Well-behaved crawlers check it before crawling and follow its rules.
A typical WordPress robots.txt looks like this:
User-agent: *
Disallow: /wp-admin/
Allow: /wp-admin/admin-ajax.php
Sitemap: https://www.example.com/sitemap_index.xml
Here's what the lines mean:
- User-agent: which crawler the rules apply to.
*means all crawlers. - Disallow: paths crawlers should not fetch.
- Allow: exceptions inside a disallowed path.
- Sitemap: the full URL of your sitemap, which helps crawlers find it.
What robots.txt does not do
This is the most misunderstood part. robots.txt controls crawling, not indexing. If you block a page in robots.txt, Google can still index its URL if other sites link to it, usually showing it without a description.
To keep a page out of search results, use a noindex meta tag or header instead, and make sure the page is not blocked in robots.txt. Google has to be able to crawl the page to see the noindex instruction.
robots.txt is also not a security tool. The file is public, and badly behaved bots ignore it. Protect private areas with passwords or proper access controls.
Common mistakes to avoid
Blocking the whole site by accident
This line tells every crawler to stay away from everything:
User-agent: *
Disallow: /
It sometimes gets left behind when a staging site goes live. In WordPress, also check Settings > Reading and make sure "Discourage search engines from indexing this site" is unchecked on your live site.
Blocking CSS and JavaScript
Google renders pages much like a browser does. If you block the folders that hold your stylesheets and scripts, Google may not see your pages properly. Leave those resources crawlable.
Listing noindexed or redirected URLs in your sitemap
This sends mixed signals. Your sitemap says "index this" while the page says "don't." Keep them consistent.
Forgetting the sitemap after a migration
If you change domains or switch from http to https, make sure your sitemap uses the new URLs and resubmit it. Our guide to moving a site without downtime covers the wider process.
How to create or edit these files
On WordPress
An SEO plugin is the easiest route. Yoast SEO and Rank Math both generate sitemaps automatically and include a robots.txt editor. If you don't use a plugin, WordPress serves a virtual robots.txt and its built-in sitemap.
On any host
You can create a physical robots.txt file in your site's root folder (usually public_html) using your control panel's File Manager or FTP. A physical file takes priority over a virtual one generated by WordPress. Save it as plain text, named exactly robots.txt in lowercase.
Submitting your sitemap to search engines
- Open Google Search Console and choose your property.
- Go to Sitemaps, enter your sitemap URL and click Submit.
- Check the status after a while to make sure Google could read it.
If you haven't set up Search Console yet, start with our Search Console setup guide. You can submit your sitemap to Bing Webmaster Tools the same way. Adding the Sitemap: line to robots.txt also helps any crawler find it.
Quick checklist
- Your sitemap loads in a browser and lists your important pages.
- It only includes canonical, indexable URLs that return 200.
- robots.txt exists at your root domain and doesn't block important content, CSS or JavaScript.
- robots.txt includes a
Sitemap:line. - Pages you want hidden from search use
noindex, not a robots.txt block. - The sitemap is submitted in Google Search Console with no errors.
Wrapping up
Sitemaps and robots.txt aren't ranking tricks. They're housekeeping that helps search engines spend their time on the right pages. Set them up once, check them after any big site change, and you'll avoid some of the most common and most painful technical SEO mistakes.
Related reading: Schema Markup for Beginners: How to Add Structured Data to Your Website; How to Set Up Google Search Console for Your Website (Step by Step).