Hi all,
when we click to a product now we have
how I can change to
www.mysite.com/sometext/product.html
Thanks in advance..
Solved! Go to Solution.
You can modify the url rewrite rule as you wanted in catalog->url rewrite management.
If you are looking for an automatic solution, rewrite Mage_Catalog_Model_Url::getProductRequestPath method,
if ($category->getLevel() > 1) { // To ensure, that category has path either from attribute or generated now $this->_addCategoryUrlPath($category); $categoryUrl = Mage::helper('catalog/category')->getCategoryUrlPath($category->getUrlPath(), false, $storeId); $requestPath = $categoryUrl . '/' . $urlKey; } else { $requestPath = 'something/' . $urlKey; }
You can modify the url rewrite rule as you wanted in catalog->url rewrite management.
If you are looking for an automatic solution, rewrite Mage_Catalog_Model_Url::getProductRequestPath method,
if ($category->getLevel() > 1) { // To ensure, that category has path either from attribute or generated now $this->_addCategoryUrlPath($category); $categoryUrl = Mage::helper('catalog/category')->getCategoryUrlPath($category->getUrlPath(), false, $storeId); $requestPath = $categoryUrl . '/' . $urlKey; } else { $requestPath = 'something/' . $urlKey; }
Is /sometext/ is your category name ? If so then you can enable it from System >> Configuration >> Catalog >> Search Engine Optimization. Choose Yes for "Use categories path for product URLs".
But if not like any text other text want to insert then you can manage it through URL rewrite Management. Don't do any change into code level its not good practice.
Menu - Catalog >> URL Rewrite Management
1. Click to add new url and choose Products from create URL rewrite.
2. select Or search your product and if ask for category selection then skip that part.
3. Over url rewrite form add your custom url into Request Path field. (E.x - sometext/product.html) And save it and clear cache and reindex.
Now check same on frontend it should be work.
Hope it helps you, Good luck
Why is rewirting code not a good practice? Imagin if he has millions of products to maintain, its not easy to update rewrite rules menually and not missing any rules.
But of course if he only need to modify a few rules, he can use the url write manager like I mentioned before.
Thanks alot!!