Jump to content

Remove category from product url


Recommended Posts

At some point, my products url looks like:
www.mysite.com/idproduct-product-name.html

But now, all my products links are:
www.mysite.com/category/idproduct-product-name.html
Without any changes in htaccess

How can I remove category from product link? I want them to show like in the first link.

Link to comment
Share on other sites

  • 2 months later...

You have to modify classes/Link.php. Find the function "public function getProductLink" (line 37)

and replace the entire function (lines 37 to 48) with

public function getProductLink($id_product, $alias = NULL, $category = NULL, $ean13 = NULL)
   {
        if (!isset($this->allow)) $this->allow = 0;
       if (is_object($id_product))
           return ($this->allow == 1)?(_PS_BASE_URL_.__PS_BASE_URI__.intval($id_product->id).'-'.$id_product->link_rewrite.($id_product->ean13 ? '-'.$id_product->ean13 : '').'.html') : 
           (_PS_BASE_URL_.__PS_BASE_URI__.'product.php?id_product='.intval($id_product->id));
       elseif ($alias)
           return ($this->allow == 1)?(_PS_BASE_URL_.__PS_BASE_URI__.intval($id_product).'-'.$alias.($ean13 ? '-'.$ean13 : '').'.html') : 
           (_PS_BASE_URL_.__PS_BASE_URI__.'product.php?id_product='.intval($id_product));
       else
           return _PS_BASE_URL_.__PS_BASE_URI__.'product.php?id_product='.intval($id_product);
   }

Link to comment
Share on other sites

  • 1 year later...
  • 1 year later...
  • 9 months later...

Hi,

 

I see several prestashop folders that do not have category subfolders in their product friendly url, in my PS1.4 seems like category is added to every product URL.I often change subcategory and not having it included into product url will help avoiding 404 errors.

 

I tried to edit only link.php as suggested above removing category from getproductlink function and it seems to work fine in localhost. Is that really all I need to do or I risk errors in the future?

 

Thanks

 

You have to modify classes/Link.php. Find the function "public function getProductLink" (line 37)

 

and replace the entire function (lines 37 to 48) with

public function getProductLink($id_product, $alias = NULL, $category = NULL, $ean13 = NULL)
{
	 if (!isset($this->allow)) $this->allow = 0;
	if (is_object($id_product))
		return ($this->allow == 1)?(_PS_BASE_URL_.__PS_BASE_URI__.intval($id_product->id).'-'.$id_product->link_rewrite.($id_product->ean13 ? '-'.$id_product->ean13 : '').'.html') :
		(_PS_BASE_URL_.__PS_BASE_URI__.'product.php?id_product='.intval($id_product->id));
	elseif ($alias)
		return ($this->allow == 1)?(_PS_BASE_URL_.__PS_BASE_URI__.intval($id_product).'-'.$alias.($ean13 ? '-'.$ean13 : '').'.html') :
		(_PS_BASE_URL_.__PS_BASE_URI__.'product.php?id_product='.intval($id_product));
	else
		return _PS_BASE_URL_.__PS_BASE_URI__.'product.php?id_product='.intval($id_product);
}

Link to comment
Share on other sites

×
×
  • Create New...