I need to display only first level category inside product url. If visitors browse and click product inside categorylevel1/categorylevel2.html, I need to show domain.com/categorylevel1/product.html and NOT domain.com/categorylevel1/categorylevel2/product.html

Is there any easy way to do that?

  • Did you find a solution? Does the answer provided work? I'm looking for the same funcionality.
    – Artur Rain
    Commented Oct 27, 2015 at 12:09
  • I didn't find any solution, but I didn't made any further research, I just simple didn't use second level categories but I went with only one level structure.
    – JohnyFree
    Commented Oct 27, 2015 at 20:41

1 Answer 1


You can get product url path form Url Rewrite collection

$path = Mage::getResourceModel('core/url_rewrite')->getRequestPathByIdPath('product/{product_id}/{category_id}', Mage::app()->getStore());


{product_id} => your product Id 
{category_id} => your first level category id.

Now you can get the product Url like



$this->getUrl('', array('_direct' => $path));

Note: product must be assign with both category (i.e., first level and second level category)

I have refer this link

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.