Magento E-commerce Platform Q/ A

Custom Redirect from a Category Page in Magento

Let's assume your customer needs to redirect store users when they click on some category link to some particular product page. You can do it by creating a simple module. 

The structure of the etc/config.xml file:



Using the above code we've rewritten default Mage_Catalog_CategoryController controller to Ikantam_Redirect_CategoryController.

Now we will add an additional parameter to the category

Code: sql/redirect_setup/install-


$installer = $this;
/** adding category attribute */
$installer->addAttribute('catalog_category', 'redirect_category_source', array(
    'group'         => 'General Information',
    'type'          => 'varchar',
    'label'         => 'Custom redirect to',
    'input'         => 'text',
    'required'      => false,
    'sort_order'    => 90,
    'global'        => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_WEBSITE


Thus we have created additional parameter: 'redirect_category_source’ in 'General Information' tab titled 'Custom redirect to'. See the screenshot:


With the help of this parameter the site admin will enable a custom redirect from this category by entering the URL and saving the configuration.

Also we need to create the controller that will be checking presence of the added parameter.

Code: CategoryController.php:

class Ikantam_Redirect_CategoryController extends Mage_Core_Controller_Front_Action
protected function _initCatagory()
        Mage::dispatchEvent('catalog_controller_category_init_before', array('controller_action' => $this));
        $categoryId = (int) $this->getRequest()->getParam('id', false);
        if (!$categoryId) {
            return false;

        $category = Mage::getModel('catalog/category')

        if (!Mage::helper('catalog/category')->canShow($category)) {
            return false;
        Mage::register('current_category', $category);
/*Redirect code*/
	$url = $category->getRedirectCategorySource();
	if (!empty($url)) {
		$url = $category->getRedirectCategorySource();
        try {
                    'category' => $category,
                    'controller_action' => $this
        } catch (Mage_Core_Exception $e) {
            return false;
        return $category;

That's it.