psergiu Posted January 28, 2013 Share Posted January 28, 2013 Hi, I have a question about formatting the friendly URL for category and subcategory and getting the matching products. I am using PrestaShop 1.5.2.0 Let's say we have a structure like this: Category 1 - Spare Parts - Accessories Category 2 - Chips - Accessories I want to display the link like this: /category-1/accessories and to display the products from category 1->accessories. How can I achieve this? The current behavior is when I click on accessories, being in category 1, the link is /accessories and the products that are displayed belong from both /category-1/accessories and /category-2/accessories Thanks! Link to comment Share on other sites More sharing options...
polaram Posted February 7, 2013 Share Posted February 7, 2013 Hi, Here is solution. //Change in classes/Dispatcher.php //line number 60 'category_rule' => array( 'controller' => 'category', 'rule' => '{category:/}{id}-{rewrite}/', 'keywords' => array( 'id' => array('regexp' => '[0-9]+', 'param' => 'id_category'), 'category' => array('regexp' => '[_a-zA-Z0-9-\pL]*'), 'rewrite' => array('regexp' => '[_a-zA-Z0-9-\pL]*'), 'meta_keywords' => array('regexp' => '[_a-zA-Z0-9-\pL]*'), 'meta_title' => array('regexp' => '[_a-zA-Z0-9-\pL]*'), ), ), these two bold lines not there in current file //classes/Link.php line number 155 just update this function public function getCategoryLink($category, $alias = null, $id_lang = null, $selected_filters = null) { if (!$id_lang) $id_lang = Context::getContext()->language->id; $url = _PS_BASE_URL_.__PS_BASE_URI__.$this->getLangLink($id_lang); if (!is_object($category)) $category = new Category($category, $id_lang); // Set available keywords $params = array(); $params['id'] = $category->id; $params['rewrite'] = (!$alias) ? $category->link_rewrite : $alias; $params['meta_keywords'] = Tools::str2url($category->meta_keywords); $params['meta_title'] = Tools::str2url($category->meta_title); $pcategory= new Category($category->id_parent, $id_lang); if($category->id_parent!=1 && $category->id_parent!=2) $params['category'] = $pcategory->link_rewrite; // Selected filters is used by the module blocklayered $selected_filters = is_null($selected_filters) ? '' : $selected_filters; if (empty($selected_filters)) $rule = 'category_rule'; else { $rule = 'layered_rule'; $params['selected_filters'] = $selected_filters; } return $url.Dispatcher::getInstance()->createUrl($rule, $id_lang, $params, $this->allow); } got to admin Preferences->seo & Url Change Route to category to this {category:/}{id}-{rewrite}/ This if my first reply to prestashop forum. I am working on prestashop from last 2 and half year. I will keep updating forum. Thanks Link to comment Share on other sites More sharing options...
Dmit Posted February 8, 2013 Share Posted February 8, 2013 (edited) Not all subdirectory displays. Product: my.com/zapchasti/zapchasti-dlja-apple/displei-/3-displej-dlja-ipad2.html Category: my.com/zapchasti-dlja-apple/displei-/ Edited February 8, 2013 by Dmit (see edit history) Link to comment Share on other sites More sharing options...
polaram Posted February 8, 2013 Share Posted February 8, 2013 It works till first parent only not recursive Link to comment Share on other sites More sharing options...
doubleD Posted February 8, 2013 Share Posted February 8, 2013 (edited) It works till first parent only not recursive For recursive (Editing the lines posted by polaram): ==============CLASSES/Dispatcher.php=============== 'rule' => '{categories:/}{id}-{rewrite}/', 'categories' => array('regexp' => '[/_a-zA-Z0-9-\pL]*'), ==============CLASSES/Link.php===================== $cats = array(); foreach ($category->getParentsCategories() as $cat) if (!in_array($cat['id_category'], array(1, 2, $category->id)))//remove root, home and current category from the URL $cats[] = $cat['link_rewrite']; $params['categories'] = implode('/', array_reverse($cats)); Edited February 8, 2013 by doubleD (see edit history) 2 Link to comment Share on other sites More sharing options...
psergiu Posted February 10, 2013 Author Share Posted February 10, 2013 Thank you for your replies. I will give it a try. Link to comment Share on other sites More sharing options...
cool and charming Posted February 15, 2013 Share Posted February 15, 2013 were can i find this...? got to admin Preferences->seo & Url Change Route to category to this {category:/}{id}-{rewrite}/ Link to comment Share on other sites More sharing options...
doubleD Posted February 15, 2013 Share Posted February 15, 2013 were can i find this...? ????? BackOffice->Preferences->Seo&URL SCREENSHOT Link to comment Share on other sites More sharing options...
cool and charming Posted February 15, 2013 Share Posted February 15, 2013 i could not find the scheme of urls...! i am able to see only these things in prestashop1.5.3 Set up URLs : Set shop URL" Robots file generation Link to comment Share on other sites More sharing options...
doubleD Posted February 15, 2013 Share Posted February 15, 2013 (edited) i could not find the scheme of urls...! i am able to see only these things in prestashop1.5.3 Set up URLs : Set shop URL" Robots file generation Friendly URL and Automatically redirect to Canonical URL should be set to 'YES' Edited February 17, 2013 by doubleD (see edit history) Link to comment Share on other sites More sharing options...
BuB Posted February 24, 2013 Share Posted February 24, 2013 I'm not getting it to work. This is already in my dispatcher.php 'category_rule' => array( 'controller' => 'category', 'rule' => '{id}-{rewrite}', 'keywords' => array( 'id' => array('regexp' => '[0-9]+', 'param' => 'id_category'), 'rewrite' => array('regexp' => '[_a-zA-Z0-9-\pL]*'), 'meta_keywords' => array('regexp' => '[_a-zA-Z0-9-\pL]*'), 'meta_title' => array('regexp' => '[_a-zA-Z0-9-\pL]*'), ), Should i replace 'rule' => '{id}-{rewrite}', with 'rule' => '{categories:/}{id}-{rewrite}/', ? Link to comment Share on other sites More sharing options...
doubleD Posted February 24, 2013 Share Posted February 24, 2013 I'm not getting it to work. This is already in my dispatcher.php Should i replace 'rule' => '{id}-{rewrite}', with 'rule' => '{categories:/}{id}-{rewrite}/', ? Yes. In Dispatcher in should be: In Link.php in should be: // Set available keywords $params = array(); $params['id'] = $category->id; $params['rewrite'] = (!$alias) ? $category->link_rewrite : $alias; $params['meta_keywords'] = Tools::str2url($category->meta_keywords); $params['meta_title'] = Tools::str2url($category->meta_title); $cats = array(); foreach ($category->getParentsCategories() as $cat) if (!in_array($cat['id_category'], array(1, 2, $category->id)))//remove root, home and current category from the URL $cats[] = $cat['link_rewrite']; $params['categories'] = implode('/', array_reverse($cats)); // Selected filters is used by the module blocklayered $selected_filters = is_null($selected_filters) ? '' : $selected_filters; 'category_rule' => array( 'controller' => 'category', 'rule' => '{categories:/}{id}-{rewrite}/', 'keywords' => array( 'id' => array('regexp' => '[0-9]+', 'param' => 'id_category'), 'categories' => array('regexp' => '[/_a-zA-Z0-9-\pL]*'), 'rewrite' => array('regexp' => '[_a-zA-Z0-9-\pL]*'), 'meta_keywords' => array('regexp' => '[_a-zA-Z0-9-\pL]*'), 'meta_title' => array('regexp' => '[_a-zA-Z0-9-\pL]*'), ), And route should be {categories:/}{id}-{rewrite}/ Link to comment Share on other sites More sharing options...
BuB Posted February 24, 2013 Share Posted February 24, 2013 (edited) I don't really understand it. Now I get this: http://www.wifinetwe...es=access-point And I want http://www.wifinetwe...s-point/indoor/ How should I do that? I also get the message: The route {categories:/}{id}-{rewrite}/ is not valid This is my dispatcher 'category_rule' => array( 'controller' => 'category', 'rule' => '{categories:/}{id}-{rewrite}/', 'keywords' => array( 'id' => array('regexp' => '[0-9]+', 'param' => 'id_category'), 'categories' => array('regexp' => '[/_a-zA-Z0-9-\pL]*'), 'rewrite' => array('regexp' => '[_a-zA-Z0-9-\pL]*'), 'meta_keywords' => array('regexp' => '[_a-zA-Z0-9-\pL]*'), 'meta_title' => array('regexp' => '[_a-zA-Z0-9-\pL]*'), ), ), And this is in link.php: public function getCategoryLink($category, $alias = null, $id_lang = null, $selected_filters = null) { if (!$id_lang) $id_lang = Context::getContext()->language->id; $url = _PS_BASE_URL_.__PS_BASE_URI__.$this->getLangLink($id_lang); if (!is_object($category)) $category = new Category($category, $id_lang); // Set available keywords $params = array(); $params['id'] = $category->id; $params['rewrite'] = (!$alias) ? $category->link_rewrite : $alias; $params['meta_keywords'] = Tools::str2url($category->meta_keywords); $params['meta_title'] = Tools::str2url($category->meta_title); $cats = array(); foreach ($category->getParentsCategories() as $cat) if (!in_array($cat['id_category'], array(1, 2, $category->id)))//remove root, home and current category from the URL $cats[] = $cat['link_rewrite']; $params['categories'] = implode('/', array_reverse($cats)); // Selected filters is used by the module blocklayered $selected_filters = is_null($selected_filters) ? '' : $selected_filters; Edited February 24, 2013 by BuB (see edit history) Link to comment Share on other sites More sharing options...
doubleD Posted February 24, 2013 Share Posted February 24, 2013 I don't really understand it. Now I get this: http://www.wifinetwe...es=access-point And I want http://www.wifinetwe...s-point/indoor/ How should I do that? I also get the message: The route {categories:/}{id}-{rewrite}/ is not valid Make sure you don't have 'space' before or after {categories:/}{id}-{rewrite}/ Link to comment Share on other sites More sharing options...
BuB Posted February 24, 2013 Share Posted February 24, 2013 Still not working. Can it have something to do with the fact that I'm also using this http://www.prestashop.com/forums/topic/204935-override-friendly-urls-without-id-number-for-v15/ (vershion 0.22). Link to comment Share on other sites More sharing options...
doubleD Posted February 24, 2013 Share Posted February 24, 2013 Still not working. Can it have something to do with the fact that I'm also using this http://www.prestasho...number-for-v15/ (vershion 0.22). I'm pretty sure it can... Will check it out. Link to comment Share on other sites More sharing options...
doubleD Posted February 24, 2013 Share Posted February 24, 2013 You need to make changes to override/classes/Dispatcher.php 'category_rule' => array( 'controller' => 'category', 'rule' => '{categories:/}{rewrite}/', 'keywords' => array( 'id' => array('regexp' => '[0-9]+'), 'rewrite' => array('regexp' => '[_a-zA-Z0-9-\pL]*', 'param' => 'category_rewrite'), 'categories' => array('regexp' => '[/_a-zA-Z0-9-\pL]*'), 'meta_keywords' => array('regexp' => '[_a-zA-Z0-9-\pL]*'), 'meta_title' => array('regexp' => '[_a-zA-Z0-9-\pL]*'), ), ), The Link php changes are OK Then go to Seo&Url and place {categories:/}{rewrite}/ instead of {categories:/}{id}-{rewrite}/ Link to comment Share on other sites More sharing options...
BuB Posted February 24, 2013 Share Posted February 24, 2013 (edited) I'm getting the numbers again I removed with the removeURL solution. Dispatcher.php and link.php as mentioned obove, but it's not working as you can see on http://www.wifinetwerken.nl/ EDIT: missed your last post, gonna try it now Edited February 24, 2013 by BuB (see edit history) Link to comment Share on other sites More sharing options...
doubleD Posted February 24, 2013 Share Posted February 24, 2013 I'm getting the numbers again I removed with the removeURL solution. Dispatcher.php and link.php as mentioned obove, but it's not working as you can see on http://www.wifinetwerken.nl/ EDIT: missed your last post, gonna try it now Still not working. Can it have something to do with the fact that I'm also using this http://www.prestasho...number-for-v15/ (vershion 0.22). I 've noticed there is a 0.23 version posted by lapy90 which already includes the override... Link to comment Share on other sites More sharing options...
BuB Posted February 24, 2013 Share Posted February 24, 2013 Thank you very much, it's finally working! Link to comment Share on other sites More sharing options...
aqwzsx159 Posted March 18, 2013 Share Posted March 18, 2013 Hi, How to add .html in category url and delete /content/ in cms url!! Ho to delete /fr/ if fr is the default language or /en/ en is the default aqwzsx159 Link to comment Share on other sites More sharing options...
doubleD Posted March 18, 2013 Share Posted March 18, 2013 (edited) Hi, How to add .html in category url and delete /content/ in cms url!! Ho to delete /fr/ if fr is the default language or /en/ en is the default aqwzsx159 Prestashop 1.5... Q: How to add .html in category? A: This one won't be easy to do... For now(as i know), the category link should end with slash ("/") sign at the end of url... Q: How to delete /content/ in cms url? A: Go to BackOffice->Settings->Seo&URL and change Route to CMS to {rewrite}/ Q: How to delete /fr/ if fr is the default language or /en/ if en is the default language ... ? A: No answer for this one too... But i agree it's a really good idea Edited March 18, 2013 by doubleD (see edit history) Link to comment Share on other sites More sharing options...
aqwzsx159 Posted March 18, 2013 Share Posted March 18, 2013 Hello doubleD, Q: How to delete /content/ in cms url? A: Go to BackOffice->Settings->Seo&URL and change Route to CMS to that don't work ! aqwzsx159 Link to comment Share on other sites More sharing options...
doubleD Posted March 18, 2013 Share Posted March 18, 2013 (edited) Hello doubleD, Q: How to delete /content/ in cms url? A: Go to BackOffice->Settings->Seo&URL and change Route to CMS to that don't work ! aqwzsx159 Is there any live link to see? Prestashop 1.5.3.1 - > link Edited March 18, 2013 by doubleD (see edit history) Link to comment Share on other sites More sharing options...
aqwzsx159 Posted March 18, 2013 Share Posted March 18, 2013 (edited) Is there any live link to see? Prestashop 1.5.3.1 - > link in 1.5.2 that don't work!!!! and {id}-{rewrite}/ id is required Edited March 18, 2013 by aqwzsx159 (see edit history) Link to comment Share on other sites More sharing options...
doubleD Posted March 18, 2013 Share Posted March 18, 2013 in 1.5.2 that don't work!!!! and {id}-{rewrite}/ id is required Update to the latest vesrsion or post a screenshot, link, live website link ... Link to comment Share on other sites More sharing options...
Dmit Posted May 14, 2013 Share Posted May 14, 2013 work for PS 1.5.4.1??? Link to comment Share on other sites More sharing options...
Cril Posted May 22, 2013 Share Posted May 22, 2013 work for PS 1.5.4.1??? It seems it doesn't work on 1.5.4.1. Made it to rewrite them as I wish, but it gives a 404 error . Link to comment Share on other sites More sharing options...
Zanys Posted June 25, 2013 Share Posted June 25, 2013 (edited) Any solution for 1.5.4. * please? EDIT: No, still don´t work Category URL with subcategory in URL. CleanURL not working. EDIT 2: Solution is here - http://www.prestashop.com/forums/index.php?/topic/204935-override-friendly-urls-without-id-number-for-v15/page__view__findpost__p__1286867 Edited July 1, 2013 by Zanys (see edit history) Link to comment Share on other sites More sharing options...
sslayer Posted July 4, 2013 Share Posted July 4, 2013 great solutions! thanks Link to comment Share on other sites More sharing options...
Galoper Posted October 20, 2013 Share Posted October 20, 2013 Great post, thank you!! it works well on PS 1.5.6. but {id} needs to stay there. Do you know a way that root "Home" could also appear in the url ? I mean .../home/category/subcategory As far as "Home" name can be, multilingual, changed by a key word, we believe this could also help with SEO. Link to comment Share on other sites More sharing options...
rrosenblatt88 Posted March 1, 2014 Share Posted March 1, 2014 (edited) Help! I was making changes to a site based on this string and now the entire site is down, and I can't even access the admin panel. I tried reverting all the changes but I don't see that fixing anything... __ Nevermind it was cached. Edited March 2, 2014 by rrosenblatt88 (see edit history) Link to comment Share on other sites More sharing options...
Mooty Posted April 3, 2014 Share Posted April 3, 2014 Help! I was making changes to a site based on this string and now the entire site is down, and I can't even access the admin panel. I tried reverting all the changes but I don't see that fixing anything... __ Nevermind it was cached. Erase .htaccess and undo changes on override and try again Link to comment Share on other sites More sharing options...
balotz Posted September 23, 2014 Share Posted September 23, 2014 Update to the latest vesrsion or post a screenshot, link, live website link ... hello there!...awesome thread, but nobody mentioned subcategory and category urls. when I set up everything like you said, product page is ok, but when I visit category page it shows me home/categoryname-id/?categories= and for subcategory home/subcategoryname-id/?categories= and it should be for cat home/categoryname/ for subcat home/categoryname/subcategoryname/ thank you! Link to comment Share on other sites More sharing options...
andrew.irpin Posted April 15, 2015 Share Posted April 15, 2015 This solution works fine with Prestashop 1.6 , but I have one question. I have product pages: {rewrite}/p{id}/ And category pages: {categories:/}{rewrite}/c{id}/ And then I have URL for exaple: http://site.com/product-ipod/p1780/ - everything works fine, but then i use http://site.com/product-ipod/p1780 - without "/" - i have 404 error. I can make the rule in htaccess file ta add "/" at the end of every url , but i have many pages in index like prices-drop, new-products and other tpl pages without "/" . And then htaccess rule add it to utl http://site.comprices-drop/ I have 404 error. Can you tell me solution to make a rule - to add " / " to url if it is needed. Link to comment Share on other sites More sharing options...
anconstantinescu Posted April 23, 2015 Share Posted April 23, 2015 hello there!...awesome thread, but nobody mentioned subcategory and category urls. when I set up everything like you said, product page is ok, but when I visit category page it shows me home/categoryname-id/?categories= and for subcategory home/subcategoryname-id/?categories= and it should be for cat home/categoryname/ for subcat home/categoryname/subcategoryname/ thank you! You did not add the rule in the dispatcher 'categories' => array('regexp' => '[/_a-zA-Z0-9-\pL]*'), Mind the extra "/" character in the regexp as opposed to the first example on this topic. Runs great with 1.6. So thanks for the solution! Link to comment Share on other sites More sharing options...
anconstantinescu Posted August 27, 2015 Share Posted August 27, 2015 In presta 1.6.1.1 there is no longer an option to enter categories as a keyword in the Route to category section of the Backoffice. Can you guys think of a good way around this? Link to comment Share on other sites More sharing options...
tomakali Posted September 10, 2015 Share Posted September 10, 2015 Hi, how to have breadcrumb menu structure in Friendly URL??? Link to comment Share on other sites More sharing options...
mesotek Posted December 4, 2015 Share Posted December 4, 2015 Hi, Here is solution. //Change in classes/Dispatcher.php //line number 60 'category_rule' => array( 'controller' => 'category', 'rule' => '{category:/}{id}-{rewrite}/', 'keywords' => array( 'id' => array('regexp' => '[0-9]+', 'param' => 'id_category'), 'category' => array('regexp' => '[_a-zA-Z0-9-\pL]*'), 'rewrite' => array('regexp' => '[_a-zA-Z0-9-\pL]*'), 'meta_keywords' => array('regexp' => '[_a-zA-Z0-9-\pL]*'), 'meta_title' => array('regexp' => '[_a-zA-Z0-9-\pL]*'), ), ), these two bold lines not there in current file //classes/Link.php line number 155 just update this function public function getCategoryLink($category, $alias = null, $id_lang = null, $selected_filters = null) { if (!$id_lang) $id_lang = Context::getContext()->language->id; $url = _PS_BASE_URL_.__PS_BASE_URI__.$this->getLangLink($id_lang); if (!is_object($category)) $category = new Category($category, $id_lang); // Set available keywords $params = array(); $params['id'] = $category->id; $params['rewrite'] = (!$alias) ? $category->link_rewrite : $alias; $params['meta_keywords'] = Tools::str2url($category->meta_keywords); $params['meta_title'] = Tools::str2url($category->meta_title); $pcategory= new Category($category->id_parent, $id_lang); if($category->id_parent!=1 && $category->id_parent!=2) $params['category'] = $pcategory->link_rewrite; // Selected filters is used by the module blocklayered $selected_filters = is_null($selected_filters) ? '' : $selected_filters; if (empty($selected_filters)) $rule = 'category_rule'; else { $rule = 'layered_rule'; $params['selected_filters'] = $selected_filters; } return $url.Dispatcher::getInstance()->createUrl($rule, $id_lang, $params, $this->allow); } got to admin Preferences->seo & Url Change Route to category to this {category:/}{id}-{rewrite}/ This if my first reply to prestashop forum. I am working on prestashop from last 2 and half year. I will keep updating forum. Thanks Hi, I have followed your above steps, MY actual structure which i want: myurl.com/maincategory/subcategory/pagename.html Till here its working fine: myurl.com/maincategory/subcategory/ After following your steps, coming below: myurl.com/subcategory/pagename.html But i want also myurl.com/maincategory/subcategory/pagename.html Could you please help, Thanks Link to comment Share on other sites More sharing options...
abhimanyu_rishi Posted October 12, 2016 Share Posted October 12, 2016 (edited) For recursive (Editing the lines posted by polaram): ==============CLASSES/Dispatcher.php=============== 'rule' => '{categories:/}{id}-{rewrite}/', 'categories' => array('regexp' => '[/_a-zA-Z0-9-\pL]*'),==============CLASSES/Link.php===================== $cats = array(); foreach ($category->getParentsCategories() as $cat) if (!in_array($cat['id_category'], array(1, 2, $category->id)))//remove root, home and current category from the URL $cats[] = $cat['link_rewrite']; $params['categories'] = implode('/', array_reverse($cats)); Hi, This code works for me but only till two level of category (i.e. home>>category>sub category). My shop has sub sub categories also. I tried to make changes as below but did not work. Either 3rd level categories are not working or product page is showing 404 error. ==============CLASSES/Dispatcher.php=============== 'rule' => '{categories:/}{id}-{rewrite}/', 'categories' => array('regexp' => '[_a-zA-Z0-9-\pL]*'), I had to remove / from 'categories' => array('regexp' => '[/_a-zA-Z0-9-\pL]*'), above as when I add it the products links shows 404 error but the 3rd level category links works. I also tried to make below changes to link.php by adding 3, in array of line 3 but did not work either ==============CLASSES/Link.php===================== $cats = array(); foreach ($category->getParentsCategories() as $cat) if (!in_array($cat['id_category'], array(1, 2, 3, $category->id)))//remove root, home and current category from the URL $cats[] = $cat['link_rewrite']; $params['categories'] = implode('/', array_reverse($cats)); Any way to work around the same code for 3 levels of category tree & not get 404 errors on product page? Thanks. Edited October 12, 2016 by abhimanyu_rishi (see edit history) Link to comment Share on other sites More sharing options...
jass82 Posted March 15, 2017 Share Posted March 15, 2017 Hi friend,I read alls post and i make the changes in dispatcher.php and link.php and work fine.But i want the same in product page mydomain.com/maincategory/subcategory/product.I'm modiffy in link.php getProductLink and i think i have to modify this if ($dispatcher->hasKeyword('product_rule', $id_lang, 'categories', $id_shop)) { $params['category'] = (!$category) ? $product->category : $category; $cats = array(); foreach ($product->getParentCategories($id_lang) as $cat) { if (!in_array($cat['id_category'], Link::$category_disable_rewrite)) { //remove root and home category from the URL $cats[] = $cat['link_rewrite']; } } $params['categories'] = implode('/', $cats); } but i put this and dont work,.... $cats = array(); foreach ($category->getParentsCategories() as $cat) if (!in_array($cat['id_category'], array(1, 2, $category->id)))//remove root, home and current category from the URL $cats[] = $cat['link_rewrite']; $params['categories'] = implode('/', array_reverse($cats)); Link to comment Share on other sites More sharing options...
SergioE Posted September 9, 2017 Share Posted September 9, 2017 Works in Ps 1.7? Link to comment Share on other sites More sharing options...
Inform-All Posted September 25, 2017 Share Posted September 25, 2017 For Prestashop 1.7 (PS1.7.2.2) i managed to get the same by doing this: in classes/Link.php add the following to getCategoryLink if ($dispatcher->hasKeyword('category_rule', $idLang, 'parent_categories', $idShop)) { $category = $this->getCategoryObject($category, $idLang); //RETRIEVING ALL THE PARENT CATEGORIES $cats = array(); foreach ($category->getParentsCategories($idLang) as $cat) { if (!in_array($cat['id_category'], array(1, 2, $category->id))) { //remove root, home and current category from the URL //HACK, category_id is added by hand, better would be to generate the subpaths via //Dispatcher but quickfix $cats[] = $cat['id_category']."_".$cat['link_rewrite']; } } // // //THE CATEGORIES ARE BEING ASSIGNED IN THE WRONG ORDER (?) $params['parent_categories'] = implode('/', array_reverse($cats));//ADD THE URL SLASHES TO THE CATEGORIES IN REVERSE ORDER } In classes/Dispatcher.php this replace 'category_rule' with this: 'category_rule' => array( 'controller' => 'category', 'rule' => '{parent_categories:/}{rewrite}/', 'keywords' => array( 'id' => array('regexp' => '[0-9]+', 'param' => 'id_category'), 'rewrite' => array('regexp' => '[_a-zA-Z0-9\pL\pS-]*'), 'meta_keywords' => array('regexp' => '[_a-zA-Z0-9-\pL]*'), 'meta_title' => array('regexp' => '[_a-zA-Z0-9-\pL]*'), 'parent_categories' => array('regexp' => '[_a-zA-Z0-9-\pL]*'), ), ), It's a nasty quick fix, but it does the job. 1 Link to comment Share on other sites More sharing options...
Grafeco Posted May 16, 2018 Share Posted May 16, 2018 Anybody know the solution for Prestashop 1.6? Thank you. Link to comment Share on other sites More sharing options...
thehurricane Posted July 25, 2018 Share Posted July 25, 2018 On 25.09.2017 at 12:16 PM, Inform-All said: For Prestashop 1.7 (PS1.7.2.2) i managed to get the same by doing this: in classes/Link.php add the following to getCategoryLink if ($dispatcher->hasKeyword('category_rule', $idLang, 'parent_categories', $idShop)) { $category = $this->getCategoryObject($category, $idLang); //RETRIEVING ALL THE PARENT CATEGORIES $cats = array(); foreach ($category->getParentsCategories($idLang) as $cat) { if (!in_array($cat['id_category'], array(1, 2, $category->id))) { //remove root, home and current category from the URL //HACK, category_id is added by hand, better would be to generate the subpaths via //Dispatcher but quickfix $cats[] = $cat['id_category']."_".$cat['link_rewrite']; } } // // //THE CATEGORIES ARE BEING ASSIGNED IN THE WRONG ORDER (?) $params['parent_categories'] = implode('/', array_reverse($cats));//ADD THE URL SLASHES TO THE CATEGORIES IN REVERSE ORDER } In classes/Dispatcher.php this replace 'category_rule' with this: 'category_rule' => array( 'controller' => 'category', 'rule' => '{parent_categories:/}{rewrite}/', 'keywords' => array( 'id' => array('regexp' => '[0-9]+', 'param' => 'id_category'), 'rewrite' => array('regexp' => '[_a-zA-Z0-9\pL\pS-]*'), 'meta_keywords' => array('regexp' => '[_a-zA-Z0-9-\pL]*'), 'meta_title' => array('regexp' => '[_a-zA-Z0-9-\pL]*'), 'parent_categories' => array('regexp' => '[_a-zA-Z0-9-\pL]*'), ), ), It's a nasty quick fix, but it does the job. Are You sure it works? I have 404 error ... I've deleted this in Link.php and added Your code. PRestashop 1.7.2.2 if ($dispatcher->hasKeyword($rule, $idLang, 'meta_keywords', $idShop)) { $category = $this->getCategoryObject($category, $idLang); $params['meta_keywords'] = Tools::str2url($category->getFieldByLang('meta_keywords')); } if ($dispatcher->hasKeyword($rule, $idLang, 'meta_title', $idShop)) { $category = $this->getCategoryObject($category, $idLang); $params['meta_title'] = Tools::str2url($category->getFieldByLang('meta_title')); } Link to comment Share on other sites More sharing options...
thehurricane Posted August 9, 2018 Share Posted August 9, 2018 Anyone made this in Prestashop 1.7?? I've made this Inform-All way, and I still have 404 error ;/ Link to comment Share on other sites More sharing options...
Inform-All Posted October 29, 2018 Share Posted October 29, 2018 Sorry for the late response, did you also rebuild the .htaccess after the changes? Besides what might make a problem is if you have (sub) category's with the same name. As i said it's a quick and nasty fix that worked for me. Link to comment Share on other sites More sharing options...
Miroo Posted March 9, 2019 Share Posted March 9, 2019 It's work but you have add {id}-{parent_categories} in presta. thx @Inform-All Link to comment Share on other sites More sharing options...
CORIYATSIA Posted March 13, 2019 Share Posted March 13, 2019 On 2/15/2013 at 12:47 PM, cool and charming said: were can i find this...? got to admin Preferences->seo & Url Change Route to category to this {category:/}{id}-{rewrite}/ I have a question about formatting the friendly URL for category and subcategory and getting the matching products. I am using PrestaShop 1.5.2.0 Link to comment Share on other sites More sharing options...
Idroclic Posted April 18, 2019 Share Posted April 18, 2019 On 9/25/2017 at 12:16 PM, Inform-All said: For Prestashop 1.7 (PS1.7.2.2) i managed to get the same by doing this: in classes/Link.php add the following to getCategoryLink if ($dispatcher->hasKeyword('category_rule', $idLang, 'parent_categories', $idShop)) { $category = $this->getCategoryObject($category, $idLang); //RETRIEVING ALL THE PARENT CATEGORIES $cats = array(); foreach ($category->getParentsCategories($idLang) as $cat) { if (!in_array($cat['id_category'], array(1, 2, $category->id))) { //remove root, home and current category from the URL //HACK, category_id is added by hand, better would be to generate the subpaths via //Dispatcher but quickfix $cats[] = $cat['id_category']."_".$cat['link_rewrite']; } } // // //THE CATEGORIES ARE BEING ASSIGNED IN THE WRONG ORDER (?) $params['parent_categories'] = implode('/', array_reverse($cats));//ADD THE URL SLASHES TO THE CATEGORIES IN REVERSE ORDER } In classes/Dispatcher.php this replace 'category_rule' with this: 'category_rule' => array( 'controller' => 'category', 'rule' => '{parent_categories:/}{rewrite}/', 'keywords' => array( 'id' => array('regexp' => '[0-9]+', 'param' => 'id_category'), 'rewrite' => array('regexp' => '[_a-zA-Z0-9\pL\pS-]*'), 'meta_keywords' => array('regexp' => '[_a-zA-Z0-9-\pL]*'), 'meta_title' => array('regexp' => '[_a-zA-Z0-9-\pL]*'), 'parent_categories' => array('regexp' => '[_a-zA-Z0-9-\pL]*'), ), ), It's a nasty quick fix, but it does the job. Hi, i follow your post but i obtain an error 500 Prestashop 1.7.4.4 Link to comment Share on other sites More sharing options...
DanieleDev Posted October 9, 2019 Share Posted October 9, 2019 Good morning, does anyone know how to fix the problem in prestashop 1.7.5? Link to comment Share on other sites More sharing options...
marsaldev Posted October 9, 2019 Share Posted October 9, 2019 Hi guys, here's the working hotfix, step by step, it's in Italian, but I think that with google translate you can follow the simple instructions 😊 Have fun Link to comment Share on other sites More sharing options...
AquaDream Posted December 18, 2019 Share Posted December 18, 2019 On 10/9/2019 at 7:54 PM, marsaldev said: Hi guys, here's the working hotfix, step by step, it's in Italian, but I think that with google translate you can follow the simple instructions 😊 Have fun It works on PS 1.7.6.1 but it gives me a 404 error on manufacturers page. e.g. https://mydomainname/el/brands/6-kormoran anybody else facing the same issue? Link to comment Share on other sites More sharing options...
marsaldev Posted December 19, 2019 Share Posted December 19, 2019 It's weird, because the edit doesn't touch the manufacturers url 🤔 Link to comment Share on other sites More sharing options...
AquaDream Posted January 15, 2020 Share Posted January 15, 2020 I know. And it happens to cms links too... Link to comment Share on other sites More sharing options...
cycy Posted February 3, 2020 Share Posted February 3, 2020 Hello, this post helped me a lot but I have another concern about the canonical url link. For this method, everything works except the canonical link, we should have for the canonical link: monsite.com/rewrite_produit that's what I'm being asked, but with the modifications above it doesn't work. I'm also asked to keep this structure for the categories in the url: either monsite.com/categories/rewrite Has anyone ever had this problem before? I know it's specific, but I've been stuck on this for days... Thank you so much for your help. Link to comment Share on other sites More sharing options...
artigianidelweb Posted May 29, 2020 Share Posted May 29, 2020 (edited) On 1/15/2020 at 2:27 PM, AquaDream said: I know. And it happens to cms links too... yes, it happens to me too. it can't be used Edited May 29, 2020 by artigianidelweb (see edit history) Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now