Steps to reproduce
- Magento 2.1.0 and Nginx with https://github.com/magento/magento2/blob/2.1.0/nginx.conf.sample
- Go to Stores > Settings: Configuration > Catalog: XML Sitemap > Products Options
- Set Add Images into Sitemap to “All”
- Go to Marketing > SEO & Search: Site Map
- Add and generate sitemap
Expected result
- URL of images shouldn’t contain pub directory.
<image:image>
<image:loc>
https://example.com/media/catalog/product/s/a/sample-product-img.jpg
</image:loc>
<image:title>Sample product</image:title>
<image:caption>Sample product</image:caption>
</image:image>
<PageMap xmlns="http://www.google.com/schemas/sitemap-pagemap/1.0">
<DataObject type="thumbnail">
<Attribute name="name" value="Sample product"/>
<Attribute name="src" value="https://example.com/media/catalog/product/s/a/sample-product-img.jpg"/>
</DataObject>
</PageMap>
Actual result
- Images are “404 Not Found”
<image:image>
<image:loc>
https://example.com/pub/media/catalog/product/s/a/sample-product-img.jpg
</image:loc>
<image:title>Sample product</image:title>
<image:caption>Sample product</image:caption>
</image:image>
<PageMap xmlns="http://www.google.com/schemas/sitemap-pagemap/1.0">
<DataObject type="thumbnail">
<Attribute name="name" value="Sample product"/>
<Attribute name="src" value="https://example.com/pub/media/catalog/product/s/a/sample-product-img.jpg"/>
</DataObject>
</PageMap>
Why hasn’t the issue been fixed in 2 years?
Still exist in 2.2.6 Backend generated sitemap.xml contains /pup/ in image src, when shops root is in /pup/.
Workaround by hostep works for me. Set generation time some minutes past to current time and generate sitemap with “bin/magento cron:run” generates sitemap without /pup/ in image path. Then I set frequency to monthly to not overwrite by automation.
I haven’t verified it it is still true on the latest version, but we definitely had the same problem with Magento 2.1.3 or 2.1.4 if I remember correctly.
We could work around it by setting the configurations:
{{unsecure_base_url}}media/{{secure_base_url}}media/By default, these fields are empty and the ‘pub’ directory part was getting added to the image paths in the sitemap.xml files.
Be aware that you should test this with the ‘pub’ directory being used as docroot.
@IlnitskiyArtem: not sure if this helps? If you want I can test again using a plain vanilla Magento setup.
@IlnitskiyArtem Ok, I was able to reproduce this again in Magento 2.1.7 I forgot this bug was triggered by the cronjobs. If you generate the sitemap.xml file using the adminhtml, there is no problem, it only happens when you let the sitemap.xml file generate using the cronjobs.
So steps to reproduce:
php bin/magento cron:runa couple of times until the generation of the sitemap.xml is triggered by this commandWould be great if this could be fixed! The workaround mentioned above gets us around the issue, but not all Magento customers will discover this workaround, so a fix would be appreciated 😃
Thanks!