How to use the Sitemap directive in robots.txt
guide // , 4 min read, by Darthwares
You use the Sitemap directive in robots.txt by adding a line containing the word Sitemap, a colon, and the absolute URL of your sitemap file. This tells search engine crawlers where to find your sitemap so they can discover the pages on your site. A robots.txt file is usually placed in the root of a website, such as https://example.com/robots.txt. Major search engines like Google and Bing support this directive to discover listed page locations.
On this page // 6 sections
The short version
- Add the Sitemap directive anywhere in your robots.txt file using a fully qualified URL.
- You can include multiple Sitemap lines or reference a single sitemap index file.
- The sitemap URL does not have to be hosted on the same domain as your robots.txt file.
- Sitemaps indicate content to crawl, while robots.txt rules define crawling permissions.
What is the syntax for the Sitemap directive?
The syntax for the Sitemap directive requires the word Sitemap, followed by a colon, a space, and the full address of your sitemap file. Google documents that the URL must be a fully qualified absolute URL including the protocol and host, such as https://example.com/sitemap.xml. Google does not assume or check alternate HTTP, HTTPS, www, or non-www protocols or hosts.
Unlike standard path rules in robots.txt files, the Sitemap directive does not support the asterisk wildcard character for prefixes, suffixes, or string patterns. The sitemap field points directly to the location of a sitemap or sitemap index file and does not require URL-encoding.
Where should you place the Sitemap directive in robots.txt?
You can place the Sitemap directive anywhere inside your robots.txt file because it is independent of user-agent groups. Specifications published by sitemaps.org note that the location within the file does not matter. The directive is not tied to any specific user agent line and may be followed by all web crawlers, provided the sitemap line is not disallowed for crawling.
The RFC Editor specification for the Robots Exclusion Protocol states that crawlers may interpret additional records like Sitemaps leniently. However, parsing these extra records must not interfere with explicitly defined records in Section 2. For example, a Sitemap record must not terminate a user-agent group.
Can you include multiple sitemaps or sitemap index files?
You can include multiple Sitemap directives in a single robots.txt file, or reference a single sitemap index file. Google Search Central and sitemaps.org state there is no limit to the number of sitemap files you can include. If your website uses a sitemap index file, you only need to declare the location of that index file rather than listing every individual sitemap contained inside it.
The sitemap file does not need to reside on the same host as the robots.txt file. This flexibility allows site owners to host cross-site sitemaps in a single location and reference them for individual sites using Search Console or robots.txt.
How do crawlers use robots.txt and sitemaps together?
Search engines use robots.txt to determine crawl access and sitemaps to discover website URLs. MDN Web Docs explains that a robots.txt file is placed in the root of a website to specify whether crawlers are allowed access to an entire site or specified resources. A restrictive robots.txt file can prevent bandwidth consumption by automated search-related crawlers.
Chrome for Developers notes that sitemaps provide crawlers with a list of site URLs and information about when they were last changed. While robots.txt defines which content search engines can or cannot crawl, sitemaps are a good way to indicate which content Google should crawl. Once uploaded and tested, Google crawlers automatically find and start using your robots.txt file to guide crawl rates and search indexing.
How do you verify and debug your Sitemap directive?
Verifying your sitemap setup involves checking syntax, file placement, and host matching. Following a clear step-by-step diagnostic process ensures search engines can locate your sitemap lines without parsing errors.
- 01Confirm that the sitemap entry uses a fully qualified absolute URL including protocol and host, such as https://example.com/sitemap.xml.
- 02Ensure the Sitemap directive is placed on its own line and does not terminate or interrupt a user-agent group.
- 03Make sure that the robots.txt file for each individual site references the correct sitemap for that specific site.
| Symptom | Possible Cause | Recommended Fix |
|---|---|---|
| Crawler fails to find sitemap | Relative path used instead of fully qualified URL | Update entry to include full protocol and host domain like https://example.com/sitemap.xml |
| Syntax error in robots.txt parser | Wildcard character used in sitemap path | Remove asterisk wildcard and specify exact absolute URL |
| User-agent group parsing fails | Sitemap directive breaks group block structure | Move directive to its own line separate from user-agent rules |
Common questions
Which search engines support the Sitemap directive in robots.txt?
Google, Bing, and other major search engines support the sitemap field in robots.txt as defined by sitemaps.org.
Does the sitemap URL need to be URL-encoded?
No, Google documents that the fully qualified URL in a sitemap field does not have to be URL-encoded.
Do you need to list every sitemap file if you use a sitemap index?
No, if you have a sitemap index file, you can include the location of just that file without listing each individual sitemap inside it.
Can a sitemap URL point to a different host domain?
Yes, the sitemap URL does not have to be on the same host as the robots.txt file.
Primary sources and further reading
This article was researched and written by an AI model and published automatically. It was written from sentences that were checked to appear on the pages below, but a person has not reviewed the text. If something is wrong, tell us at chibivikramathithan@darthwares.com and we will correct it.
- Google Search Central: Build and submit a sitemap
- Google Search Central: Create and submit a robots.txt file
- Google Search Central: How Google interprets the robots.txt specification
- sitemaps.org: Sitemaps XML format
- Chrome for Developers: robots.txt is not valid audit
- RFC Editor: RFC 9309 - Robots Exclusion Protocol
- MDN Web Docs: Robots.txt