Magento 404 Error – Category URLs Not Found

404-pageadmincategoryoverridesurl-rewrite

Today just before lunch (around the time a reindex was being pushed through) the category urls started throwing up 404 errors.

Site in question:

http://www.awesomegti.com

However, if you search a product (eg: ttrs) the search works fine, as do the product links. Also all CMS pages such as company info work perfect.

Anyone got any ideas?

Ive a feeling its an issue with the Catalog URL Rewrite Reindex as this seems to fail/remain unfinished.

Any help appreciated 🙂

Best Answer

Programmatically speaking, the category page will return a noRoute/404 page when the call to _initCategory returns false.

#File: app/code/core/Mage/Catalog/controllers/CategoryController.php
if ($category = $this->_initCatagory()) {
    //...
}
elseif (!$this->getResponse()->isRedirect()) {
    $this->_forward('noRoute');
}

The _initCategory method returns false for three reasons

When a category id can't be extracted from the request,

#File: app/code/core/Mage/Catalog/controllers/CategoryController.php
$categoryId = (int) $this->getRequest()->getParam('id', false);
if (!$categoryId) {
    return false;
}

When the catalog/category helper's canShow method returns false,

#File: app/code/core/Mage/Catalog/controllers/CategoryController.php
if (!Mage::helper('catalog/category')->canShow($category)) {
    return false;
}

When an observer of the catalog_controller_category_init_after event throws an exception

#File: app/code/core/Mage/Catalog/controllers/CategoryController.php
try {
    Mage::dispatchEvent(
        'catalog_controller_category_init_after',
        array(
            'category' => $category,
            'controller_action' => $this
        )
    );
} catch (Mage_Core_Exception $e) {
    Mage::logException($e);
    return false;
}

The canShow method mentioned above returns false for three reasons.

If the category has no id,

#File: app/code/core/Mage/Catalog/Helper/Category.php
if (!$category->getId()) {
    return false;
}

The category's active property is set to false

#File: app/code/core/Mage/Catalog/Helper/Category.php
if (!$category->getIsActive()) {
    return false;
}

Or the category isn't in the root category list

#File: app/code/core/Mage/Catalog/Helper/Category.php
if (!$category->isInRootCategoryList()) {
    return false;
}

Some quick temporary debugging code in the above files should get to the bottom of your problem.

If viewAction method isn't being called, it means your rewrites aren't being created. If you're using Commerce Bug (my commercial Magento debugging extension) the Request tab will quickly tell you which controller action method is being called.

Related Topic