2

Preconditions

app/etc/env.php

'directories' => [ 'document_root_is_pub' => true ],

'MAGE_MODE' => 'production',
  • document_root_is_pub is true
  • MAGE_MODE is have production value

sitemap.xml

  • Filename : sitemap.xml
  • Path : /media/

Admin => Stores => Configuration => General => Web:

  • Base Urls => Base URL for User Media Files =>{{unsecure_base_url}}media/

  • Base URLs (Secure) => Secure Base URL for User Media Files => {{secure_base_url}}media/



But while generating the sitemap.xml via cron

Expected result

Actual result



NOTE : When sitemap is generated from admin panel sitemap contains the proper urls, But somehow with cron it comes wrong url (contains pub in the url)



Most likely reason (Might be) But not in my case

Sometime problem happens when running the sitemap generation through bin/magento cron:run from outside of the Magento directory.

  • e.g our magento code is in /var/www/src, if I run php src/bin/magento cron:run from /var/www the urls will contain src as part of the baseurl.
  • Running from the magento directory, e.g php bin/magento cron:run from /var/www/src, works as expected.
  • But my cron is generating from /var/www/src
  • And Running from ADMIN UI - Site generate will also works as expected.

Any solution or advise will be really helpful.

This question has an open bounty worth +100 reputation from Aditya Shah ending in 4 days.

Looking for an answer drawing from credible and/or official sources.

Any solution or advise would be helpful.

  • 1
    I think as you have set document_root_is_pub it true so you base_url will be like magento-site/pub that's why it will added pub in your URL. Please check by echo this {{unsecure_base_url}}media/ OR try {{(un)secure_base_url}}media/ – Divyarajsinh Aug 13 at 6:05
  • Thanks for the comment, let me check that. – Aditya Shah Aug 13 at 6:05
  • this is acknowledged internal issue magento please look -> github.com/magento/magento2/issues/5321 – Tuyen Nguyen 14 hours ago

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.