XML Sitemap: Configuration
Configuring the XML sitemap for Sylius 2: global keys with defaults, per-channel settings in the admin, images on a CDN, static pages, robots.txt and multiple channels.
XML Sitemap: Configuration
This documentation always describes the latest published version.
Configuration has two parts: the global keys in config/packages/mmd_sylius_sitemap.yaml and the per-channel settings in the admin.
Global keys
All keys are optional:
mmd_sylius_sitemap:
scheme: https
storage_dir: '%kernel.project_dir%/var/sitemap'
max_urls_per_file: 50000
max_bytes_per_file: 47185920
image_base_path: /media/image/
static_routes:
- sylius_shop_homepage
| Key | Default | Description |
|---|---|---|
scheme |
https |
Scheme of every generated absolute URL. Allowed: http and https |
storage_dir |
%kernel.project_dir%/var/sitemap |
Directory the generated files are written to, one subdirectory per channel. Must not be empty |
max_urls_per_file |
50000 |
A new file starts at this URL count. Allowed: 1 to 50000 (the protocol limit) |
max_bytes_per_file |
47185920 (45 MiB) |
A new file starts at this uncompressed size. Allowed: 1024 bytes to 52428800 bytes (50 MiB) |
image_base_path |
/media/image/ |
Public path local product images are served under |
static_routes |
[sylius_shop_homepage] |
Shop routes without parameters, listed once per language |
A file is split at whichever limit is hit first. This keeps the protocol's 50 MB limit even with many languages and images per product.
storage_dirhas to survive deployments and be writable by the user running the command and readable by the web server. How to ensure that is described under Installation and operation.
Per-channel settings
Admin sidebar → MMKreativ Plugins → XML sitemap
The page shows a grid with the columns Channel, Enabled, URLs and Last generated. "Create" adds a row per channel, and the row actions edit or delete it. There is at most one row per channel. When editing, the channel can no longer be changed so that files already generated are not orphaned.
| Setting | Default | Description |
|---|---|---|
| Enable the sitemap for this channel | off | Master switch. Only enabled channels are generated and served |
| Products | on | Include products |
| Categories | on | Include categories |
| Static pages | on | Include the home page and the routes listed in static_routes |
| Product images | on | List images per product URL (image sitemap) |
| Hreflang alternates | on | Link the language versions of a page to each other. Only has an effect with more than one language |
| Products: change frequency | weekly | Value for changefreq |
| Products: priority | 0.8 | Value for priority |
| Categories: change frequency | weekly | Value for changefreq |
| Categories: priority | 0.6 | Value for priority |
| Static pages: change frequency | monthly | Value for changefreq |
| Static pages: priority | 0.5 | Value for priority |
The change frequency accepts always, hourly, daily, weekly, monthly, yearly and never. The priority ranges from 0.0 to 1.0 in steps of 0.1 and is only a hint to search engines about relative importance within your own site. There is one value per content type for the whole channel, not one per product or category.
A channel needs a hostname and a default locale and must be enabled in Sylius. Sylius only resolves enabled channels by host, so files for a disabled channel would never be served. If any of this is missing, the generation reports an error for that channel.
Practical examples
Single-language shop with default values
Add a row for the channel WEB in the admin, tick "Enable the sitemap for this channel", save and generate. static_routes stays at sylius_shop_homepage.
Shop with images on a CDN
If the product images live on a CDN and Sylius stores an absolute URL in the image path (for example https://cdn.example.com/media/product.jpg), the plugin uses that URL as it is. image_base_path only applies to paths without http:// or https://. If local images are served under a different path, adjust it:
mmd_sylius_sitemap:
image_base_path: /uploads/products/
Adding more static pages
Any shop route without parameters can be included. Add your own routes next to the home page:
mmd_sylius_sitemap:
static_routes:
- sylius_shop_homepage
- app_shop_imprint
- app_shop_about
app_shop_imprint and app_shop_about stand for routes of your own application. Each route appears once per language of the channel.
Own storage directory on persistent storage
mmd_sylius_sitemap:
storage_dir: /var/shared/sitemap
Announcing it in robots.txt
The sitemap is served at https://<channel host>/sitemap-index.xml. Add it to the robots.txt of the respective host:
Sitemap: https://shop.example.com/sitemap-index.xml
The plugin provides no Twig function and no
robots.txt. You add the line yourself to therobots.txtyour shop serves.
Multiple channels
Add a separate row for every channel. Each channel gets its own files under storage_dir/<channel code>/ and is served on its own host.