How to Generate and Configure XML Sitemap in Magento 2
XML sitemaps help search engines discover and index your store's pages efficiently. Magento 2 can generate sitemaps that include product URLs, category URLs, and CMS page URLs. Proper sitemap configuration ensures search engines can crawl your store completely and stay updated with content changes.
Configuring Sitemap Generation
Admin Settings
Navigate to Stores → Configuration → Catalog → XML Sitemap to configure:
Category Options:
- Frequency: How often categories change (daily, weekly, monthly)
- Priority: Priority relative to other URL types (0.0 – 1.0, where 0.5 is typical for categories)
Product Options:
- Frequency: How often products change
- Priority: Product pages are typically given higher priority (0.8 – 1.0)
- Add Images into Sitemap: Include product image URLs (recommended for Google image search)
CMS Page Options:
- Frequency: How often CMS pages change
- Priority: Usually lower priority (0.25 – 0.5)
Generation Settings:
- Enabled: Yes
- Start Time: Schedule generation during low-traffic hours
- Frequency: Daily is recommended for active stores
- Error Email Recipient: Email address for generation failure notifications
Creating a Sitemap Entry
Go to Marketing → SEO & Search → Site Map and click Add Sitemap:
- Filename:
sitemap.xml - Path:
/(root of the Magento installation) - Store View: Select the store view this sitemap applies to
Click Save & Generate to create the sitemap immediately.
Cron-Based Auto-Generation
Once configured, Magento generates sitemaps via cron according to the schedule set in the admin. Ensure cron is properly configured -- sitemap generation will not run without it.
See also: How to Set Up and Troubleshoot Cron Jobs in Magento 2
Manual Generation via CLI
If cron-based generation fails or you need immediate generation:
php bin/magento mirasvit:seositemap:generate --all
For standard Magento sitemap generation without third-party extensions, generate from the admin panel by going to Marketing → SEO & Search → Site Map, selecting the sitemap, and clicking Generate.
Troubleshooting
Generation Timeouts
Large stores with tens of thousands of products may experience timeouts during sitemap generation. The HTTP request that triggers generation from the admin panel has a limited execution time.
Solutions:
- Generate via CLI instead of the admin panel (no HTTP timeout limit)
- Increase
max_execution_timein php.ini for CLI:php -d max_execution_time=0 bin/magento cron:run - Split sitemaps by store view rather than generating a single large sitemap
Image Processing Warnings
Sitemap generation with product images enabled may produce PNG library warnings if the server's image processing libraries (GD or Imagick) are misconfigured or outdated.
Symptoms:
- Warning messages in the generation log about image processing
- Sitemap generation fails partway through or produces an incomplete file
Solutions:
- Verify image library installation:
php -m | grep -E 'gd|imagick' - Update the image processing library to the latest version
- If the issue persists, temporarily disable "Add Images into Sitemap" to generate a text-only sitemap
Sitemap Not Updating
If the sitemap file exists but contains stale data:
- Verify cron is running: check
cron_scheduletable for recent sitemap-related entries - Check file permissions: the web server user must have write access to the sitemap path
- Check the generation log for errors:
var/log/directory
Submitting to Google Search Console
After generating the sitemap:
- Log in to Google Search Console
- Select your property
- Go to Sitemaps in the left menu
- Enter the sitemap URL (e.g.,
https://example.com/sitemap.xml) - Click Submit
Google will periodically re-fetch the sitemap. Monitor the submission status for errors (invalid URLs, unreachable pages).
Multi-Store Sitemap Handling
Each store view should have its own sitemap file. When configuring sitemaps:
- Create separate sitemap entries for each store view
- Use distinct filenames (e.g.,
sitemap_en.xml,sitemap_de.xml) - Submit each sitemap separately to Google Search Console
- After multi-store configuration changes, regenerate all sitemaps
If using a sitemap index file, ensure it references all store-specific sitemaps.
robots.txt
Add the sitemap URL to your robots.txt file so search engines can discover it automatically:
Sitemap: https://example.com/sitemap.xml
Sitemap: https://example.com/sitemap_de.xml