Skip to content

Sitemap

Module: Magenx_Sitemap · no GraphQL changes

Magento’s sitemap lists its own theme’s URLs, such as men/tops/blue-jacket.html. The storefront serves different ones, such as /en/product/blue-jacket. Without this module every sitemap URL is a 404. This module rewrites the URLs while Magento generates the sitemap.

Magento writesThe storefront serves
men/tops.html/en/category/men/tops
men/tops/blue-jacket.html/en/product/blue-jacket
about-us/en/about-us
home page/en

For each product, category and CMS page:

  1. The .html suffix is removed.
  2. A product keeps only its URL key, without the category path.
  3. The type prefix is added: product, category, or nothing for CMS pages.
  4. The store view’s locale prefix is added, for example en.
  5. The home page becomes the store root: /en, never /en/home.

Settings are per store view, so each locale gets its own prefix.

  1. Install the module. It ships switched off.
  2. For each store view, go to Stores > Configuration > Magenx > Sitemap URLs, set Store Path Prefix to the storefront locale, and set Rewrite Sitemap URLs to Yes.
  3. In Marketing > SEO & Search > Site Map, add one sitemap per store view, each with its own file name.
  4. Generate them, then check that one product, one category, one CMS page and the home page each open on the storefront.
Sitemap URLs settings in the admin: Rewrite Sitemap URLs, Store Path Prefix and Strip URL Suffix, then the category, product and CMS page path prefixes
Stores > Configuration > Magenx > Sitemap URLs.

Limits:

  • Magento’s optional batch sitemap generation is not covered: its product URLs are not rewritten. The admin button and the standard sitemap_generate cron job are covered.
  • Product image URLs keep Magento’s media URL.
  • If robots.txt points at a single /sitemap.xml, make that file a sitemap index of the per-store-view sitemaps.

Configure

  1. The admin switches rewriting on for the German store view and sets the store prefix "de".
  2. Entity prefixes keep their defaults.

Generate

  1. The admin (or the schedule) generates the German sitemap.
  2. Entries are rewritten: herren/oberteile.html → de/category/herren/oberteile; herren/oberteile/blaue-jacke.html → de/product/blaue-jacke; ueber-uns → de/ueber-uns; home → de.
  3. The host part still comes from the store's base address.

Verify

  1. One product, one category, one content page and the home entry each open on the storefront.

These always hold:

  • With rewriting off, the sitemap is unchanged.
  • Rewriting never changes stored URLs or catalog data.
  • One store view's settings never affect another store view's sitemap.
  • Product = [store]/[product prefix]/[product key].
  • Category = [store]/[category prefix]/[path without suffix].
  • Content page = [store]/[page prefix]/[identifier]; home = [store].
SituationWhat happens
Rewriting on, store prefix empty.No store segment; no leading double slash.
No catalog suffix configured.Nothing removed.
Product path without category.de/product/<key>.
Entry already absolute.Unchanged.
Home page identifier "home".de, never de/home.
Path ending in the suffix twice.Only the final suffix removed.
  • Store views with rewriting on; standard generation.
  • Generating the sitemap or sitemap index (existing generation does that).
  • Changing image addresses.
  • Optimised bulk generation modes that bypass normal item collection.
  • Adding storefront-only pages (blog, deals).
  • Serving the file from the storefront (deployment).
Terminal window
composer require magenxcommerce/module-sitemap
bin/magento module:enable Magenx_Sitemap
bin/magento setup:upgrade
bin/magento setup:di:compile # production mode only
bin/magento cache:flush
  • PHP ~8.4.0||~8.5.0, Magento 2.4.8.

Stores > Configuration > Magenx > Sitemap URLs

General

SettingDefaultScopeNotes
Rewrite Sitemap URLs
magenx_sitemap/general/enabled
NoStore viewYes/No. Rewrites every URL in the generated XML sitemap into the headless storefront's route shape. Off means Magento's own paths are written unchanged.
Store Path Prefix
magenx_sitemap/general/store_path_prefix
emptyStore viewText. Shown when Rewrite Sitemap URLs = Yes. Leading path segment for this store view, normally the storefront locale (for example "en" for https://example.com/en/product/blue-jacket). Set it per store view; leave empty for a store served at the site root.
Strip URL Suffix
magenx_sitemap/general/strip_url_suffix
YesStore viewYes/No. Shown when Rewrite Sitemap URLs = Yes. Removes the catalog URL suffix (Catalog > SEO, usually ".html") from product and category URLs, which the storefront routes do not use.

Categories

SettingDefaultScopeNotes
Category Path Prefix
magenx_sitemap/category/path_prefix
categoryStore viewText. Shown when enabled = Yes. Inserted between the store path prefix and the category URL path, producing /{store prefix}/{prefix}/men/tops. Leave empty to keep the bare category path.

Products

SettingDefaultScopeNotes
Product Path Prefix
magenx_sitemap/product/path_prefix
productStore viewText. Shown when enabled = Yes. Inserted between the store path prefix and the product URL, producing /{store prefix}/{prefix}/blue-jacket. Leave empty to keep the bare product path.
Use Product URL Key Only
magenx_sitemap/product/url_key_only
YesStore viewYes/No. Shown when enabled = Yes. Drops any category path from the product URL (men/tops/blue-jacket becomes blue-jacket). Required when "Use Categories Path for Product URLs" is enabled, because the storefront product route is a single segment.

CMS Pages

SettingDefaultScopeNotes
CMS Page Path Prefix
magenx_sitemap/cms/path_prefix
emptyStore viewText. Shown when enabled = Yes. Inserted between the store path prefix and the CMS page identifier. Leave empty for storefronts that serve CMS pages at /{store prefix}/{identifier}. The configured home page always collapses to the store root.

Grant these under System > Permissions > User Roles > Role Resources:

ResourceUnderID
Sitemap URLs ConfigurationStores > Settings > ConfigurationMagenx_Sitemap::config
TermMeaning
Sitemap entryOne address the sitemap lists.
Store prefixLeading path segment for a store view, usually its locale ("en").
Entity prefixSegment before product ("product"), category ("category") or content page addresses.
SuffixLegacy file suffix on catalog addresses, e.g. ".html".
Product keyLast path segment of a product address.
Home pageThe content page configured as the store's home.