# Improve SEO with a Sitemap

Sitemaps provide search crawlers with instructions on the pages to index and the site hierarchy, which can improve your SEO rankings. Submitting a sitemap to tools such as Google Search Console can also help identify broken links or duplicate content. B2C Commerce includes sitemap management features for:

- [Storefront Reference Architecture (SFRA)](https://developer.salesforce.com/docs/commerce/sfra/guide/sfra-overview.md) and SiteGenesis (SG) ecommerce sites
- Headless ecommerce applications like those built on [Progressive Web App (PWA) Kit](https://developer.salesforce.com/docs/commerce/pwa-kit-managed-runtime/guide)

This guide explains how to create and upload a sitemap for a headless site built on B2C Commerce.

## Supported Implementations

You can use the sitemap feature for headless sites if you built your site on B2C Commerce with any of these storefront implementations:

- Composable Storefront (PWA Kit) for your whole site
- A [hybrid storefront](/docs/commerce/b2c-commerce/guide/hybrid-implementation.md) (SG/SFRA and PWA Kit)
- Your own bespoke headless implementation

:::note
Unless otherwise stated, the steps in this guide apply to all three implementations.
:::

:::tip
- If your routes are configured in Business Manager, create a sitemap in Business Manager. See [Create a Sitemap](#create-a-sitemap).
- If your routes aren’t configured in Business Manager, create a sitemap or supplement your existing sitemap by using this API endpoint: [uploadCustomSitemapAndTriggerSitemapGeneration](https://developer.salesforce.com/docs/commerce/commerce-api/references/seo?meta=uploadCustomSitemapAndTriggerSitemapGeneration).
:::

## Create a Sitemap

1. If you haven’t done so already, set up a vanity domain in embedded CDN (eCDN).

:::note
If you’re not routing your site traffic directly to eCDN, create a subdomain such as `seo.example.com` to serve your sitemap. Replace `example.com` with your vanity domain name.
:::

2. In Business Manager (BM), [configure a hostname alias](https://help.salesforce.com/s/articleView?id=cc.b2c_configuring_hostname_alias.htm\&type=5) for your site that matches your vanity domain.
3. In BM, [generate a sitemap](https://help.salesforce.com/s/articleView?id=cc.b2c_generating_sitemaps.htm\&type=5). You can find your sitemap at `example.com/sitemap_index.xml`. Replace “example.com” with your vanity domain name.
4. Update your existing `robots.txt` file in your PWA Kit or headless site with `example.com/sitemap_index.xml`.
5. If you have a hybrid storefront project (SFRA and PWA Kit) then also:
   - [Generate a robots.txt file](https://help.salesforce.com/s/articleView?id=cc.b2c_generating_a_robots_txt_file.htm\&type=5).
   - [Verify the robots.txt file](https://help.salesforce.com/s/articleView?id=cc.b2c_verifying_the_robots_txt_location.htm\&type=5).
6. [Notify search engines about your B2C Commerce sitemap](https://help.salesforce.com/s/articleView?id=cc.b2c_notifying_search_engines_about_your_sitemap.htm\&type=5).

## Upload Your Sitemap to Your Domain's Root

Improve your site's visibility, user experience, and efficiency by uploading your site map to your domain's root. In your PWA Kit project:

1. In [`ssr.template-retail-react-app/app/ssr.js`](https://github.com/SalesforceCommerceCloud/pwa-kit/blob/9d645adfcec3a36f7d8aa410a669c150f57aca14/packages/template-retail-react-app/app/ssr.js#L109), add a path to your sitemap. For example:

   `app.get('/sitemap_index.xml', runtime.serveStaticFile('static/sitemap_index.xml'))`

2. Update the `ssrShared` property in [`template-retail-react-app/config/default.js`](https://github.com/SalesforceCommerceCloud/pwa-kit/blob/develop/packages/template-retail-react-app/config/default.js#L45-L50) so that your sitemap is available to the server-side rendering system. For example:

```jsx
   ssrShared:[
   'static/sitemap_index.xml'..]
```

3. [Deploy your bundle](https://developer.salesforce.com/docs/commerce/pwa-kit-managed-runtime/guide/pushing-and-deploying-bundles.md) to your chosen environment.
4. Confirm that your sitemap is available in your domain's root. In this example, replace `test-env.example.com` with the path that applies to your deployed environment:

   `test-env.example.com/sitemap_index.xml`

## Best Practices

- Make sure that your sitemap incorporates all the crucial pages that you want search engines to find and index. This includes product listing pages, product detail pages, blog posts, and other relevant content.
- If your sitemap becomes very large, consider using priority settings in BM. You can use these settings to indicate which pages are most important for search engines to crawl first. See [Generate Sitemaps in B2C Commerce](https://help.salesforce.com/s/articleView?id=cc.b2c_generating_sitemaps.htm\&type=5).
- Schedule a job to update the sitemap regularly so that search engines are aware of these changes and can index them promptly. See [Generate Sitemaps in B2C Commerce](https://help.salesforce.com/s/articleView?id=cc.b2c_generating_sitemaps.htm\&type=5).
- Review and update any crawl directives in the ` robots.txt  `file to ensure that they align with your SEO strategy and don’t block important parts of the site.
- Regularly test the accessibility of the sitemap URL to ensure that search engines and users can reach it without any issues.

## Troubleshoot Sitemaps

This section provides suggested solutions for a few common errors that you can encounter while using sitemaps.

### Incorrect URL Structure in the Sitemap

**Potential Cause:** Syntax errors or other errors in your sitemap.

**Suggested Solution:** Ensure that all URLs in the sitemap are absolute and correctly formatted. Use the correct protocol (http or https) and don’t include session IDs or other dynamic parameters. See [Generate Sitemaps in B2C Commerce](https://help.salesforce.com/s/articleView?id=cc.b2c_generating_sitemaps.htm\&type=5).

### Sitemap URLs Return Errors (404, 500)

**Potential Cause:** Inaccurate URLs in your sitemap.

**Suggested Solution:** Regularly check the URLs in your sitemap to ensure that they’re accessible and don't return errors. Fix any broken links or server issues. See [Generate Sitemaps in B2C Commerce](https://help.salesforce.com/s/articleView?id=cc.b2c_generating_sitemaps.htm\&type=5).

### Search Engines Unable to Read the robots.txt File

**Potential Cause:** Blocking directives errors or other issues in your `robots.txt` file.

**Suggested Solution:** Test the robots.txt file by using a robots.txt tester. Ensure that there are no blocking directives that prevent search engines from accessing important pages or the sitemap itself. See [Generate a Robots.txt File with Business Manage for B2C Commerce](https://help.salesforce.com/s/articleView?id=cc.b2c_generating_a_robots_txt_file.htm\&type=5).

## See Also

- [SEO API](https://developer.salesforce.com/docs/commerce/commerce-api/references/seo?meta=uploadCustomSitemapAndTriggerSitemapGeneration)
- [Sitemaps in B2C Commerce](https://help.salesforce.com/s/articleView?id=cc.b2c_sitemap_overview.htm\&language=en_US\&type=5)
- [Robots.txt Files for B2C Commerce](https://help.salesforce.com/s/articleView?id=cc.b2c_using_the_robots_txt_file_to_prevent_crawling_of_development_and_staging_instances.htm\&type=5)
- [URL Resolution](https://developer.salesforce.com/docs/commerce/commerce-api/guide/url-resolution.md)
- [SEO for B2C Commerce](https://help.salesforce.com/s/articleView?id=cc.b2c_seo_overview.htm\&language=en_US\&type=5)
