Jump to content

Category / Subcategory URL


Recommended Posts

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

  • 2 weeks later...

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

  On 2/8/2013 at 5:41 AM, polaram said:

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 by doubleD (see edit history)
  • Like 2
Link to comment
Share on other sites

  On 2/15/2013 at 12:52 PM, divya204 said:

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 by doubleD (see edit history)
Link to comment
Share on other sites

  • 2 weeks later...

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

  On 2/24/2013 at 11:17 AM, BuB said:

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

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 by BuB (see edit history)
Link to comment
Share on other sites

  On 2/24/2013 at 12:35 PM, BuB said:

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

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

  On 2/24/2013 at 1:27 PM, BuB said:

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

 

 

  On 2/24/2013 at 1:05 PM, BuB said:

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

  • 3 weeks later...
  On 3/18/2013 at 1:08 PM, aqwzsx159 said:

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 by doubleD (see edit history)
Link to comment
Share on other sites

  On 3/18/2013 at 1:52 PM, aqwzsx159 said:

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 by doubleD (see edit history)
Link to comment
Share on other sites

  • 1 month later...
  • 1 month later...
  • 2 weeks later...
  • 3 months later...

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

  • 4 months later...
  • 1 month later...
  On 3/1/2014 at 5:11 PM, rrosenblatt88 said:

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

  • 5 months later...
  On 3/18/2013 at 2:53 PM, doubleD said:

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

  • 6 months later...

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

  On 9/23/2014 at 4:22 PM, balotz said:

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

  • 4 months later...
  • 2 weeks later...
  • 2 months later...
  On 2/7/2013 at 9:29 PM, polaram said:

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

  • 10 months later...
  On 2/8/2013 at 9:00 AM, doubleD said:

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 by abhimanyu_rishi (see edit history)
Link to comment
Share on other sites

  • 5 months later...

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

  • 5 months later...
  • 3 weeks later...

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.

  • Like 1
Link to comment
Share on other sites

  • 7 months later...
  • 2 months later...
  On 9/25/2017 at 10:16 AM, 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.

Expand  

 

 

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

  • 2 weeks later...
  • 2 months later...
  • 4 months later...
  • 1 month later...
  On 9/25/2017 at 10:16 AM, 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.

Expand  

Hi, i follow your post but i obtain an error 500 :( Prestashop 1.7.4.4

Link to comment
Share on other sites

  • 5 months later...
  • 2 months later...
  On 10/9/2019 at 4: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 ;)

 

Expand  

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

  • 4 weeks later...
  • 3 weeks later...

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

  • 3 months later...
  • 4 years later...

Ok, I am having same issue. I am using the Store version 8.1.7 on a Classic Core theme. I have the following:

Category 1 (Parent Category) which is:

Catalog:
Link is normal ->/collections/

Then I have a sub category which is:

Patio, Lawn & Garden:
Link is doing this: ->/garden/ instead of /collections/garden/

Then other categories to products:
/collections/garden/fountains/

Is it possible to do this? I don't mind the id in the links.

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...