0

XML Sitemap contains a lot of non-canonical URLs in Magento 2.0.2. It's not good practice from SEO perspective and and worth fixing.

Here is my config:

  • Use Categories Path for Product URLs is set to "No"
  • Use Canonical Link Meta Tag For Products is set to "Yes"

And few lines from my sitemap:

http://example.com/women/tops-women/tanks-women/erica-evercool-sports-bra.html  (category path, Non-Canonical)
http://example.com/nora-practice-tank.html (Canonical)
...

All sitemap links should be equal to canonical links.

Could someone please have a look at it. Appreciate any help.

0

I noticed the same thing when I first generated my sitemap. I ended up making a short extension module and tweaking the sitemap query for products.

The class that needs to be extended: Magento\Sitemap\Model\ResourceModel\Catalog\Product

The function that needs to be overridden: public function getCollection($storeId)

Change the parameter in the joinLeft of the query from:

'e.entity_id = url_rewrite.entity_id AND url_rewrite.is_autogenerated = 1'

To the following:

'e.entity_id = url_rewrite.entity_id AND url_rewrite.is_autogenerated = 1 AND url_rewrite.metadata is null'

This works for me. I'm obviously not doing a check for the canonical configuration setting and just scoping on the meta-data field in the query. This HAS NOT been thoroughly tested, so I make no promises that this won't exclude products for some reason.

I hope this helps. Maybe there will be an official patch for this later, but for now this is my solution.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.