Mar 28, 2015
kalpesh

Magento EE 1.14 – Broken category & product sitemap URLs

Magento EE 1.14 introduces a bug fix which apparently becomes a bug in our website. Magento EE 1.14.0.0 Release Notes and Magento CE 1.9.0.0 Release Notes lists this in it’s Bug Fixes:
Google Sitemap files now include the .html suffix for category and product URLs.

We don’t have .html suffix in our category and product URLs, so we were good before this fix. But after upgrading it to latest version all the category and product URLs were having “.” (dot) at the end in XML sitemap. This is because Magento allows admin to give a custom suffix for category and product URLs for sitemap, but hardcodes “.” regardless of there are values in the above config fields or not. This allows unnecessary dots in all the URLs which can lead to 404 pages.

Magento Category Product URL config

Magento team have used observer to observe the events sitemap_categories_generating_before and sitemap_products_generating_before to add the suffix in the following file and functions (Notice I have commented all lines in the functions):
app/code/core/Enterprise/Catalog/Model/Observer.php
(copy this file to app/code/local/Enterprise/Catalog/Model/Observer.php, you may have to create directories)

/**
     * Add Seo suffix to category's URL if doesn't exists.
     *
     * @param Varien_Event_Observer $observer
     */
    public function addSeoSuffixToCategoryUrl(Varien_Event_Observer $observer)
    {
        /*$seoSuffix = (string) Mage::app()->getStore()->getConfig(
            Mage_Catalog_Helper_Category::XML_PATH_CATEGORY_URL_SUFFIX
        );
        $this->_addSuffixToUrl($observer->getCollection()->getItems(), $seoSuffix);*/
    }

    /**
     * Add Seo suffix to product's URL if doesn't exists.
     *
     * @param Varien_Event_Observer $observer
     */
    public function addSeoSuffixToProductUrl(Varien_Event_Observer $observer)
    {
        /*$seoSuffix = (string) Mage::app()->getStore()->getConfig(
            Mage_Catalog_Helper_Product::XML_PATH_PRODUCT_URL_SUFFIX
        );
        $this->_addSuffixToUrl($observer->getCollection()->getItems(), $seoSuffix);*/
    }

After commenting above function’s logic and generating the Google Sitemap again (Admin > Catalog > Google Sitemap) everything was normal (no dot and suffix in URLs)

1 Comment

  • Thanks for the writeup – this issue was driving me batty.

    Since we have some sites that use the suffix and some that don’t I modified your fix to only add the suffix if it exists –

    /**
         * Add Seo suffix to category's URL if doesn't exists.
         *
         * @param Varien_Event_Observer $observer
         */
        public function addSeoSuffixToCategoryUrl(Varien_Event_Observer $observer)
        {        
            $seoSuffix = (string) Mage::app()->getStore()->getConfig(
                Mage_Catalog_Helper_Category::XML_PATH_CATEGORY_URL_SUFFIX
            );
            if (strlen($seoSuffix) > 0) {
                $this->_addSuffixToUrl($observer->getCollection()->getItems(), $seoSuffix);
            }
        }

        /**
         * Add Seo suffix to product's URL if doesn't exists.
         *
         * @param Varien_Event_Observer $observer
         */
        public function addSeoSuffixToProductUrl(Varien_Event_Observer $observer)
        {
            $seoSuffix = (string) Mage::app()->getStore()->getConfig(
                Mage_Catalog_Helper_Product::XML_PATH_PRODUCT_URL_SUFFIX
            );

            if (strlen($seoSuffix) > 0) {
                $this->_addSuffixToUrl($observer->getCollection()->getItems(), $seoSuffix);
            }
        }

Leave a comment

 

Welcome to my Blog

Kalpesh MehtaHelping Magento developers in their day-to-day development problems since 2011. Most of the problems and solutions here are my own experiences while working on different projects. Enjoy the blog and don't forget to throw comments and likes/+1's/tweets on posts you like. Thanks for visiting!

Certifications

Honor

Recognition

Magento top 50 contributors

Magento top 50 contributors

Contributions