Continued Magento 1 Support ⋅ 7-Day Money-back guarantee ⋅ Implemented by a Magento Certified Developer


How to avoid duplicate content in Magento?

I'm available for Magento, PHP, Shopware or ReactJS projects.

In the field of search engine optimization (SEO) everyone tries to write the content in best quality from a customer perspective and ultimately also for the search engine. One important aspect therein is to avoid duplicate content.

In this post I will clarify what duplicate content is and show a common source of duplicate content in Magento.

What is Duplicate Content?

Duplicate content means publishing more or less the same content under different URLs. For example if you have written a blog post about how browsers handle cookies and you publish it under the URL /2020/09/browsers-restrict-cookies-2020/ and because of some automatic actions by your content management systems the post is also published under /browsers-restrict-cookies-2020/, then this probably might be duplicate content.
I write “probably” because there are ways to tell the search engine robot that one of both pages is the “master page”, e.g. via Canonical Links.

A very useful explanation of duplicate content strategies can be found at Yoast, which are very much the experts in SEO for WordPress.

How does Duplicate Content affect Magento?

But back to sources of duplicate content in Magento:
In general for most of my clients the Magento configuration option “add store code to urls” is activated. This means that you can have different Store(View)s for different countries or languages and have the German store available under the URL “www.store.test/de" and the English one at “www.store.test/en".

The problem here is that unfortunately in Magento, CMS pages then are accessible under 2 different urls. Let’s assume we have a CMS page with URL identifier test-cms-page and we have activated the store code in the configuration options mentioned above, then this CMS page with the German content is available at:

Obviously this is a real problem for duplicate content in Magento! But the fix is also very easy and I have implemented it in my Vianetz_Utilities extension for Magento 1:

final class Vianetz_Utilities_Model_CmsNoRouteObserver
{
    /**
     * Event: cms_controller_router_match_before 
     */
    public function run(Varien_Event_Observer $observer)
    {
        $condition = $observer->getEvent()->getData('condition');

        if ($this->getRequest()->getActionName() === 'noRoute') {
            $condition->setData('continue', false);
        }
    }

    /**
     * @return \Mage_Core_Controller_Request_Http|\Zend_Controller_Request_Http
     */
    private function getRequest()
    {
        return Mage::app()->getRequest();
    }
}

Therefore we implement a new observer and check if the route action name is “noRoute”. In this case we either redirect to the url with the store code or simply show a 404 (which is what the extension does).

I hope this helps you to avoid one common source of duplicate content in Magento that is there out of the box.

Posted in