Skip to content

Declare the sitemaps of every shop in robots.txt on multistore - #207

Open
ShaiMagal wants to merge 2 commits into
PrestaShop:devfrom
ShaiMagal:fix/robots-sitemap-multistore
Open

ShaiMagal wants to merge 2 commits into
PrestaShop:devfrom
ShaiMagal:fix/robots-sitemap-multistore

Conversation

@ShaiMagal

Copy link
Copy Markdown
Contributor
Questions Answers
Description? Declares the sitemap of every shop in robots.txt on multistore, instead of only the one in context. Details below.
Type? bug fix
BC breaks? no
Deprecations? no
Fixed ticket? Fixes #206
How to test? See below
Sponsor company OpenServis.cz

Why

robots.txt is a single file in the shop root and multistore serves it to every domain, but the core writes a Sitemap line only for the shop in context (Tools::generateRobotsFile()). The sitemaps of the remaining shops are then declared nowhere, and those shops are served a Sitemap line for a domain that is not theirs.

What it does

Subscribes to actionAdminMetaAfterWriteRobotsFile, which the core fires with the open file handle, and appends one Sitemap line per remaining shop using that shop's own domain and its own PS_SSL_ENABLED value. The shop in context is skipped because the core already wrote it, and only shops whose sitemap file exists and is non-empty are listed, same condition the core applies. It does nothing when multistore is off.

The hook has to reach existing installations, hence the version bump and upgrade-5.1.0.php.

How to test

  1. Multistore on, two shops on separate domains
  2. Generate the sitemap for both shops in the module
  3. Shop Parameters > Traffic & SEO > Generate robots.txt file
  4. Fetch robots.txt

Before:

# Sitemap
Sitemap: https://shop-one.example/1_index_sitemap.xml

After:

# Sitemap
Sitemap: https://shop-one.example/1_index_sitemap.xml
Sitemap: https://shop-two.example/2_index_sitemap.xml

Multiple Sitemap lines are allowed, so each domain now finds its own. Worth checking that a single-shop install produces a byte-identical file to before, and that a shop with no generated sitemap is not listed.

@github-project-automation github-project-automation Bot moved this to Ready for review in PR Dashboard Sep 1, 2026
@ShaiMagal
ShaiMagal force-pushed the fix/robots-sitemap-multistore branch from 12a2eb7 to f42d448 Compare September 1, 2026 13:56
The core builds its Sitemap line from the domain the back office is opened on
and from the base URI of the default shop. Switching the back office context to
another shop therefore leaves the sitemap of that shop undeclared on the domain
it is actually served from, which is the case this hook is meant to cover.

Rebuild the line the core has written and compare it, instead of skipping the
shop in context unconditionally. Nothing is added when both URLs match, so a
single-shop installation keeps producing the same robots.txt byte for byte.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Ready for review

Development

Successfully merging this pull request may close these issues.

Multistore: sitemaps of the other shops are never declared in robots.txt

2 participants