I am using Magento

I have created 3 root categories with multiple sub categories in each root category.

Category image

First root category (Category) works fine, but their is some issue with sub-categories of other 2 root categories. For those sub-categories it gets some weird url.

1) Category - Root category

2) Lifestyle - Root category

3) Solar Need - Root category

And if I try http://domain-name/professional.html or http://domain-name/heavy-use.html URL's for professional and heavy use sub-categories, it shows 404 error.

I cleared the cache, tried re-indexing, ran compilation, disabled compilation, but nothing seems to work.

Below is the code I am using to get the root categories and sub categories.

$html = '';

$children = $menuTree->getChildren();
$parentLevel = $menuTree->getLevel();
$childLevel = is_null($parentLevel) ? 0 : $parentLevel + 1;

$counter = 1;
$childrenCount = $children->count();

$parentPositionClass = $menuTree->getPositionClass();
$itemPositionClassPrefix = $parentPositionClass ? $parentPositionClass . '-' : 'nav-';

$baseUrl = Mage::getBaseUrl();

$html .= '<li class="new-menu level0 nav-1 first last parent"><a href="'.$baseUrl.'products">Shop Solar</a>';

$categories = Mage::getModel('catalog/category')->getCollection()
    ->addAttributeToSelect('*')//or you can just add some attributes
    ->addAttributeToFilter('level', 1)//2 is actually the first level
    ->addAttributeToFilter('is_active', 1)//if you want only active categories

if ($categories) {
    $html .= '<div class="menu-arrow"></div><ul>';
        foreach ($categories as $category) {
            $html .= '<li>';
                $html .= '<p class="menu-heading">By '.$category->getName().'</p>';
                $html .= '<ul class="child">';
                //$children = Mage::getModel('catalog/category')->getCategories($category->getID());
                $children = Mage::getModel( 'catalog/category' )->getCollection()
                    ->addFieldToFilter('parent_id',array('eq' => $category->getID()))
                    ->addFieldToFilter('is_active', array('eq' => '1'));

                if ($children) {
                    foreach ($children as $child) {
                        if ($child->getCustomIconAttribute()) {
                            $iconUrl = Mage::getBaseUrl('media').'catalog/category/'.$child->getCustomIconAttribute();
                            $iconUrl = '';

                        $html .= '<li>';
                            $html .= '<div class="menu-icon"><img src="'.$iconUrl.'" /></div>';
                            $html .= '<div class="cat-wrap"><a href="'.$child->getUrl().'">'.$child->getName().'</a>';
                            $html .= '<p class="cat-desc">'.$child->getDescription().'</p></div>';
                        $html .= '</li>';
            $html .= '</ul>';
        $html .= '</li>';
$html .= '<p class="all-prod"><a href="'.$baseUrl.'products">View All Products</a></p></ul>';

$html .= '</li>';

return $html;

Settings under Catalog->Search engine optimization settings

  • try Re-indexing Commented May 30, 2016 at 6:43
  • Tried that also, no luck.
    – danish
    Commented May 30, 2016 at 7:25
  • Do you have multi store/website for which you have created other root categories. Whats the setting you have under Catalog|Search Engine Optimization
    – Bharath
    Commented May 30, 2016 at 7:34
  • If its not multi store why do you want to create multiple root categories. A root category is parent of all sub categories for a specific store.Every root category will be specific to one store.
    – Bharath
    Commented May 30, 2016 at 7:45
  • Well does that mean it should get the name of the sub category but not the url?
    – danish
    Commented May 30, 2016 at 9:22

1 Answer 1


In order to get the URLs you mention, they must be under "Category" category root.

Category (root store category) - Portable power - Test - Professional - Heavy Use

You can't achieve what you are looking for with your current categories structure without heavily modifying/overwriting Magento core files (not advised at all).

You can try...

Category (as root store category) - Portable power - Test - Life Style - Professional - Solar Need - Heavy Use

This will give you by default URLs such as:

  • Portable power - domain-name/portable-power.html
  • Test - domainname/test.html
  • Professional - domain-name/life-style/professional.html
  • Heavy Use - domain-name/solar-need/heavy-use.html

Hope it helps.

  • Then why does magento has option to add more than 1 root category?
    – danish
    Commented Jun 4, 2016 at 4:34
  • According to Magento documentation: Because the root category is the highest level of the catalog, your store can have only one root category active at a time. You can, however, create additional root categories for alternate catalog structures, different stores, and views. [...]The root category is not visible to customers in the store, and does not have a URL key. More info: docs.magento.com/m2/ce/user_guide/catalog/category-root.html Commented Jun 5, 2016 at 16:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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