Jump to content

url rewrite without EAN code


Recommended Posts

Hi

url rewriting is working fine on my website, but I would like to improve it.

a product url looks like :

http://vincimusic.ne...6600002014.html

It means that after the category, the rewrite url of the product includes its ID and name but also the EAN code.

I would like to have rewrite url without the EAN code, so they could look like :

http://vincimusic.ne...camps-sp6s.html

My htacces lines about rewrite url for producst are :

RewriteRule ^([0-9]+)-[a-zA-Z0-9-]*\.html /product.php?id_product=$1 [QSA,L]

RewriteRule ^[a-zA-Z0-9-]*/([0-9]+)-[a-zA-Z0-9-]*\.html /product.php?id_product=$1 [QSA,L]

I don't feel secure in trying to change thoses lines and I don't know if coming back to the previous htacces file could be done safely to restore anything in case of bugs.

Can anyone tell me if the process is risky or safe ?

Is somebody skilled about manipulating rewrite rules and make disapear the ean code ?

Thanks for your help

Link to comment
Share on other sites

The friendly urls are generated in:

Folder Classes->Link.php->Function getProductLink.

To keep out the ean just append this code at start of the function

$ean13=NULL;

 

So it will see like this:

 

public function getProductLink($id_product, $alias = NULL, $category = NULL, $ean13 = NULL, $id_lang = NULL)
{

$ean13=NULL; 


 if (is_object($id_product))
  return ($this->allow == 1)?(_PS_BASE_URL_.__PS_BASE_URI__.$this->getLangLink((int)$id_lang).((isset($id_product->category) AND !empty($id_product->category) AND $id_product->category != 'home') ? $id_product->category.'/' : '').(int)$id_product->id.'-'.$id_product->link_rewrite.($id_product->ean13 ? '-'.$id_product->ean13 : '').'.html') :
  (_PS_BASE_URL_.__PS_BASE_URI__.'product.php?id_product='.(int)$id_product->id);
 elseif ($alias)
  return ($this->allow == 1)?(_PS_BASE_URL_.__PS_BASE_URI__.$this->getLangLink((int)$id_lang).(($category AND $category != 'home') ? ($category.'/') : '').(int)$id_product.'-'.$alias.($ean13 ? '-'.$ean13 : '').'.html') :
  (_PS_BASE_URL_.__PS_BASE_URI__.'product.php?id_product='.(int)$id_product);
 else
  return _PS_BASE_URL_.__PS_BASE_URI__.'product.php?id_product='.(int)$id_product;
}

 

This is the simpliest way to do it. What is does is tell the function that there is not an ean13 code, so it will ignore it.

Link to comment
Share on other sites

Hi Prescol

 

Thanks for your help on url rewrite without EAN code

 

I have appended the code at the right place of the Link.php file.

 

This leads to a blank page when accessing to my administration pannel, and same black page when accesing the website homepage.

 

You can find attached the modified Link.php file. I think the modification has been done well.

Is there something missing or wrong ?

 

Regards

Link.php

Link to comment
Share on other sites

Well,

 

I have modified the code by just adding

$ean13=NULL;

 

Then I empty my

tools>smarty>cache and

tools>smarty>compile (except index)

 

You can check the Link.php file joined.

 

What happens is :

correct url without EAN appears when mouse goes on a product link

 

But when clicking on the product link, the explorer take much more time to open the product page, and the product page url adress always has the eancode .

 

I think I must have placed the adding code a few steps of where it had to be, or there is something more to look at.

Link.php

Link to comment
Share on other sites

  • 1 year later...
×
×
  • Create New...