I have a confusion in product and category url rewrite concept. Is magento stores the url in database? If yes which table? If no how we get the category and product url from collections? like this.

$product_collection = Mage::getModel('catalog/product')->getCollection()
    ->addAttributeToFilter('entity_id', 16)
$product_collection_url = $product_collection->getFirstItem()->getProductUrl();

and what is addUrlRewrite() ? Please explain.

2 Answers 2


These questions might help to explain it:

Without addUrlRewrite you may get the URLs in the form of http://www.my site.com/catalog/product/view/id/2309/s/shopcat/category/373/ which don't look very nice!

addUrlRewrite gives the URL in the form with the URL key, eg. http://www.site.com/product-url-key.html.

Adding a category ID eg. addUrlRewrite(15) gives the category URL for that product, eg. http://www.site.com/category-15/product-url-key.html, providing the product is in that category of course!

The latter will only work if in System/Configuration/Catalog/Search Engine Optimization you have Use Categories Path for Product URLs set to Yes and Use Canonical Link Meta Tag For Products set to No. See here for more on that http://www.magentocommerce.com/knowledge-base/entry/canonical-meta-tag

Hope that helps!

  • Thanks Sarah.. So the url key is stored in table right ..? which table ..?
    – Elavarasan
    Commented Aug 31, 2014 at 8:56
  • You can see the URL key when you go into a product in the admin panel, it is one of the attributes listed (under "Status"). The URL rewrites are stored in Catalog/Url Rewrite Management too. I am not sure about the DB tables but this may help magentocommerce.com/boards/v/viewthread/246103 Would recommend sticking to the admin panel where you can though because there are a lot of tables involved with Magento products.
    – Sarah
    Commented Aug 31, 2014 at 9:02
Hi this is the example you can display the Url of Product.

         $listInstance = Mage:getBlockSingleton('catalog/product_list');

         $_productCollection =  $listInstance ->getLoadedProductCollection();

        foreach ($_productCollection as $_product)

       echo $_product->getProductUrl();// product Url

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.