Crawling & Indexing

How to Add Your Sitemap to Robots.txt

Your XML sitemap gives search engines a useful list of the pages you want them to discover. Adding its full address to robots.txt gives crawlers a consistent place to find that list. This guide shows you which sitemap URL to use, how to add it correctly, and how to check that the finished setup works.

Crawling & IndexingBeginner7 min readPublished

What is the sitemap directive in robots.txt?

The sitemap directive is a line in your robots.txt file that tells supporting crawlers where to find a sitemap for your website.

Sitemap: https://www.example.com/sitemap.xml

The part after Sitemap: must be the complete address of the sitemap, including https:// and the correct hostname. It can point to an individual sitemap or to a sitemap index that links to several smaller sitemap files.

The directive does not allow or block crawling. Your User-agent, Allow and Disallow rules continue to control crawler access separately.

Why add a sitemap to robots.txt?

A robots.txt file sits at a predictable address at the root of a site. Crawlers commonly request it before exploring other URLs, which makes it a useful place to advertise your sitemap.

  • Consistent discovery: supporting crawlers can find the sitemap without a separate manual submission.
  • One shared reference: your team has a clear record of which sitemap or sitemap index belongs to the site.
  • Support for several crawlers: the declaration is not limited to one search-engine account.
  • Cross-host sitemaps: the directive can establish the connection when a sitemap is hosted on another hostname under your control.

Adding the line does not guarantee that every sitemap URL will be crawled or indexed. A sitemap is a discovery hint. Each listed page still needs to be accessible, indexable, useful and technically sound.

It is also sensible to submit the sitemap in Google Search Console. Robots.txt helps discovery across supporting crawlers, while Search Console provides Google-specific processing information and error reporting.

Before you edit robots.txt

Find the correct sitemap and make sure it is worth declaring. Many content-management systems create one automatically, often at an address such as:

https://www.example.com/sitemap.xml
https://www.example.com/sitemap_index.xml

Open the URL in a browser and check that it loads successfully. A sitemap index should link to the individual sitemap files beneath it. An individual XML sitemap should list full page URLs.

Review the contents as well as the file itself. A useful sitemap should contain the canonical, indexable pages you want search engines to consider. Avoid filling it with redirects, error pages, duplicate URL variations or pages carrying a noindex directive.

Your robots.txt file should be available at the root of the relevant host:

https://www.example.com/robots.txt

If you use a hosted website platform, the sitemap and robots.txt file may be generated automatically. Check the platform’s search or SEO settings before editing files directly, because a manual change may be overwritten.

How to add your sitemap to robots.txt

Use the exact live hostname and add the sitemap declaration on its own line. The five checks below help you make the change at the right source and confirm what crawlers can reach.

  1. 01
    Open the live robots.txt file.

    Visit /robots.txt on the exact hostname you are checking. Confirm that you have the correct site, protocol and subdomain before changing its source file or CMS setting.

  2. 02
    Copy the sitemap’s full URL.

    Open the sitemap and copy its complete address. Keep the exact protocol, hostname, path and filename.

  3. 03
    Add a Sitemap line.

    Add the directive on its own line. It is independent of a particular User-agent group, so it does not need to sit beneath a specific crawler rule. A clear convention is to place sitemap declarations together at the end of the file.

  4. 04
    Publish the updated file.

    Save the change through the system that controls robots.txt. Then reopen the public /robots.txt URL to make sure the new line is present and has not been changed by a cache, plugin or deployment process.

  5. 05
    Test both addresses.

    Open the sitemap URL directly from the published robots.txt file. Confirm that robots.txt and the sitemap each return successfully and that the link uses the intended live hostname.

Sitemap: https://www.example.com/sitemap.xml

Examples for common sitemap setups

One XML sitemap

For a smaller site with one sitemap, declare its full URL once:

User-agent: *
Allow: /

Sitemap: https://www.example.com/sitemap.xml

The Allow: / line is optional because crawling is allowed by default when no rule blocks it. It is included here only to make the example easy to read.

A sitemap index

Larger sites often use a sitemap index that links to separate page, post, product or image sitemaps. Declare the index rather than repeating every child file:

User-agent: *
Allow: /

Sitemap: https://www.example.com/sitemap_index.xml

Several independent sitemaps

You can include more than one sitemap directive. Give each file its own line:

User-agent: *
Allow: /

Sitemap: https://www.example.com/pages-sitemap.xml
Sitemap: https://www.example.com/products-sitemap.xml
Sitemap: https://www.example.com/images-sitemap.xml

If those files are already listed inside a sitemap index, declaring the index alone is normally simpler.

How to check the finished setup

Do not stop after saving the source file. Verify what crawlers can reach on the public site.

  • Open the live robots.txt URL and find every Sitemap: line.
  • Follow each declared URL and confirm that it returns a successful response.
  • Check that the sitemap belongs to the correct host and contains full canonical URLs.
  • Run another Clearcrawl crawl and review the robots.txt and sitemap findings.
  • Submit the sitemap or sitemap index in Google Search Console if you want Google-specific status and processing errors.

If you change the sitemap URL later, update robots.txt at the same time. Remove stale declarations once the old file is no longer part of the live setup. If the sitemap still cannot be fetched, check the common sitemap errors and confirm which pages are eligible for search.

Common mistakes

01Using a relative sitemap path

Sitemap: /sitemap.xml is incomplete. Use the fully qualified URL, including the protocol and hostname.

02Declaring a sitemap that does not load

A correct-looking line cannot help if the destination returns an error, redirects unexpectedly or requires a login. Test the live response.

03Mixing HTTP, HTTPS, www and non-www versions

Use the canonical live hostname. Search engines do not treat every variation as an automatic substitute for the one you declared.

04Using the sitemap to contradict crawl or index rules

Listing a URL in a sitemap does not override robots.txt or a noindex directive. Keep your signals consistent by listing canonical, accessible and indexable URLs.

Frequently asked questions

Where should the sitemap line go in robots.txt?

It can appear anywhere in the file because it is independent of the User-agent groups. Placing sitemap declarations together at the bottom is a clear convention that makes them easy to review.

Can I add more than one sitemap to robots.txt?

Yes. Add each sitemap as a separate Sitemap: line. If you already have a sitemap index containing the child sitemaps, you can declare only the index to keep the file simpler.

Do I still need to submit my sitemap to Google Search Console?

It is not required for Google to discover a sitemap declared in robots.txt, but submission is useful. Search Console shows when Google read the file and reports processing problems that a robots.txt declaration alone will not show you.

Does adding a sitemap to robots.txt improve rankings?

Not directly. It helps supporting crawlers discover the sitemap and its URLs, but it does not make a page rank or guarantee indexing. Page quality, indexability, internal links and many other signals still matter.

Should robots.txt link to the sitemap index or every sitemap file?

Use the sitemap index when it already lists all the relevant child sitemaps. Declare separate files when they are genuinely independent or when no index file connects them.

Clearcrawl logoClearcrawl
A clearer next step

Keep robots.txt and your sitemaps working together

Crawl your website to check crawler access, robots.txt, XML sitemaps and indexability in one report. Find unavailable files, conflicting signals and affected pages before they slow discovery.

7 free days. See what Clearcrawl can find, then choose the plan that fits your site.

Try Clearcrawl free for 7 daysStart a 7-day free trial Start with Clearcrawl. Subscribe when you’re ready.

Learn more from Google