Redirect Simple Products to Configurable Parents with Options Preselected

Recently I met quite a challenge while building an extension for Magento. By default, the urls of simple child products whom belong to a configurable parent are answered with a 404. This behaviour can be easily overridden with a small extension.

Our client wanted to take it a step further. Today we will build an extension that redirects URLs of simple products to their configurable parents with options preselected.

The XML Basics

Before we start, we need to create the basic files needed for any Magento extension.

Create app/etc/modules/DaanvandenBergh_RedirectSimpleProducts.xml and add the following snippet into it:

<?xml version="1.0"?>
                <Mage_Catalog />

Then create app/code/local/DaanvandenBergh/RedirectSimpleProducts/etc/config.xml and paste the following code into it:

<?xml version="1.0"?>

Now we have everything in place for our extension to be recognized by Magento as active. Also, we’ve told Magento which classes we will be using and when our methods should be fired.

We’ve added an observer to the event when a user opens a catalog product view and provided the class and method that should be executed.

So what does this mean in regular English? It means that this extension waits for a user to open a product page and then triggers the method we provided.

Now let’s move on to where the magic happens.

Redirect Simple Product to Configurable Parent

In config.xml we specify when our extension should be triggered. In the class below we will specify what our extension should do.

Create /app/code/local/DaanvandenBergh/RedirectSimpleProducts/Model/Observer.php and add the following code:

<?php class DaanvandenBergh_RedirectSimpleProducts_Model_Observer { 
      public function redirectToConfigurable($observer) { 
          $id = Mage::app()->getRequest()->getParam('id');
          $configurableParentIds = Mage::getResourceSingleton('catalog/product_type_configurable')->getParentIdsByChild($id);

          if (isset($configurableParentIds[0])) {
              $mainProduct = Mage::getModel('catalog/product')

              $productAttributeOptions = $mainProduct->getTypeInstance(true)->getConfigurableAttributesAsArray($mainProduct);

              $attributeOptions = array();
              foreach ($productAttributeOptions as $productAttribute) {
                  $simpleProduct = Mage::getModel('catalog/product')->getCollection()
                    ->addAttributeToFilter('entity_id', array('eq' => $id))

              $attributeOptions[$productAttribute['attribute_id']] = $simpleProduct->getData($productAttribute['attribute_code']);

          Mage::app()->getResponse()->setRedirect($mainProduct->getProductUrl(), 301);
     return $this;

That’s it! Our method detects the product ID of the visited Simple Product URL and uses that to detect the ID of its configurable parent. Then it creates an array of all the available options, filters out the ones that are used by the Simple Child Product and sends it along with a 301-redirect.

The biggest upside of this approach is its SEO Friendliness. Since it uses the actual URL of the configurable parent, it doesn’t create any duplicate content. This makes this approach preferable over the approach of some premium plugins.

I hope this extension helps you. It redirects simple product URLs that are not visible in the catalog/search to their configurable parent with its options preselected. If you have any remarks or questions. Please, leave a comment!

About Daan van den Bergh
Magento 2 Back-end Developer with a passion for trainlifting, airplane-gliding, hunting trees and creating fake hobbies.


  1. Hi Thank you for your post. I would like to ask you how could I rewrite this module to make it work for Magento 2? Any advice would be appreciated, cheers.

  2. Very interesting – as with the above poster, this is exactly what I’m looking for in Magento 2.


Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.