Jump to content

Friendly urls without ID number?


krat

Recommended Posts

  • 11 months later...

FREE module available now:

http://www.prestashop.com/forums/index.php?/topic/110922-friendly-urls-without-id-number/page__view__findpost__p__883380

 

Here is what i got:

 

1st file: ./controllers/ProductController.php

 

update the function preProcess()

public function preProcess()
{
 if ($id_product = (int)Tools::getValue('id_product'))
  { $this->product = new Product($id_product, true, self::$cookie->id_lang); }
 else //remove link id by Ha!*!*y
 {
  $id_product = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('
SELECT `id_product`
FROM `'._DB_PREFIX_.'product_lang`
WHERE `link_rewrite` = \''.Tools::getValue('product_name_seo').'\'');
  $this->product = new Product($id_product, true, self::$cookie->id_lang);
 } //remove link id by Ha!*!*y
 if (!Validate::isLoadedObject($this->product))
 {
  header('HTTP/1.1 404 Not Found');
  header('Status: 404 Not Found');
 }
 else
  $this->canonicalRedirection();
 parent::preProcess();
}

 

 

2nd file: ./classes/Link.php

 

update the function getProductLink()

public function getProductLink($id_product, $alias = NULL, $category = NULL, $ean13 = NULL, $id_lang = NULL)
{
 global $cookie;
 if (is_object($id_product))
 {
  $link = '';
  if ($this->allow == 1)
  {
$link .= (_PS_BASE_URL_.__PS_BASE_URI__.$this->getLangLink((int)$id_lang));

if (isset($id_product->category) AND !empty($id_product->category) AND $id_product->category != 'home')
 $link .= $id_product->category.'/';
else
 $link .= '';
//remove link id by Ha!*!*y
//$link .= (int)$id_product->id.'-';
if (is_array($id_product->link_rewrite))
 $link.= $id_product->link_rewrite[(int)$cookie->id_lang];
else
  $link.= $id_product->link_rewrite;
if ($id_product->ean13)
 $link .='-'.$id_product->ean13;
else
 $link .= '';
$link .= '.html';
  }
  else
  {
$link .= (_PS_BASE_URL_.__PS_BASE_URI__.'product.php?id_product='.(int)$id_product->id);
  }
  return $link;
 }

 else if ($alias)
 {
  $link = '';
  if ($this->allow == 1)
  {
$link .= (_PS_BASE_URL_.__PS_BASE_URI__.$this->getLangLink((int)$id_lang));

if ($category AND $category != 'home')
 $link .= $category.'/';
else
  $link .= '';
//remove link id by Ha!*!*y
//$link .= (int)$id_product.'-'.$alias;
$link .= $alias;

if ($ean13)
 $link .='-'.$ean13;
else
 $link .= '';

$link .= '.html';
  }
  else
$link .=(_PS_BASE_URL_.__PS_BASE_URI__.'product.php?id_product='.(int)$id_product);
  return $link;
 }

 else
  return _PS_BASE_URL_.__PS_BASE_URI__.'product.php?id_product='.(int)$id_product;
}

 

3rd file: ./classes/Tools.php

 

update the function generateHtaccess()

 

find inside the function

 if ($multilang)
 {
  $tab['RewriteRule']['content']['^([a-z]{2})/[a-zA-Z0-9-]*/([0-9]+)\-[a-zA-Z0-9-]*\.html'] = 'product.php?id_product=$2&isolang=$1 [QSA,L]';
  $tab['RewriteRule']['content']['^([a-z]{2})/([0-9]+)\-[a-zA-Z0-9-]*\.html'] = 'product.php?id_product=$2&isolang=$1 [QSA,L]';

 

and add the following lines:

//remove link id by Ha!*!*y
		$tab['RewriteEngine']['content_no_id'][] = 'RewriteCond %{REQUEST_FILENAME} !-f';
		$tab['RewriteEngine']['content_no_id'][] = 'RewriteCond %{REQUEST_FILENAME} !-d';
		$tab['RewriteEngine']['content_no_id'][] = 'RewriteRule ^([a-z]{2})/[a-zA-Z0-9-]*/([a-zA-Z0-9-]*)\.html product.php?product_name_seo=$2&isolang=$1 [QSA,L]';
		$tab['RewriteEngine']['content_no_id'][] = 'RewriteCond %{REQUEST_FILENAME} !-f';
		$tab['RewriteEngine']['content_no_id'][] = 'RewriteCond %{REQUEST_FILENAME} !-d';
		$tab['RewriteEngine']['content_no_id'][] = 'RewriteRule ^([a-z]{2})/([a-zA-Z0-9-]*)\.html product.php?product_name_seo=$2&isolang=$1 [QSA,L]';
//remove link id by Ha!*!*y

 

also look for inside the function:

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

 

 

and than add the following lines:

//remove link id by Ha!*!*y
	$tab['RewriteEngine']['content_no_id'][] = 'RewriteCond %{REQUEST_FILENAME} !-f';
	$tab['RewriteEngine']['content_no_id'][] = 'RewriteCond %{REQUEST_FILENAME} !-d';
	$tab['RewriteEngine']['content_no_id'][] = 'RewriteRule ^([a-zA-Z0-9-]*)\.html product.php?product_name_seo=$1 [QSA,L]';
	$tab['RewriteEngine']['content_no_id'][] = 'RewriteCond %{REQUEST_FILENAME} !-f';
	$tab['RewriteEngine']['content_no_id'][] = 'RewriteCond %{REQUEST_FILENAME} !-d';
	$tab['RewriteEngine']['content_no_id'][] = 'RewriteRule ^[a-zA-Z0-9-]*/([a-zA-Z0-9-]*)\.html product.php?product_name_seo=$1 [QSA,L]';
//remove link id by Ha!*!*y

 

also look for inside the function:

 // Classic URL rewriting
 if ($rewrite_settings)
  foreach ($tab['RewriteRule']['content'] as $rule => $url)
fwrite($writeFd, 'RewriteRule '.$rule.' '.__PS_BASE_URI__.$url."\n");

 

add this after:

//remove link id by Ha!*!*y
 if ($rewrite_settings){
  fwrite($writeFd, "\n");
  foreach ($tab['RewriteEngine']['content_no_id'] as $line => $rule){
fwrite($writeFd, $rule."\n");
  }
 }
//remove link id by Ha!*!*y
Edited by HA!*!*Y (see edit history)
  • Like 2
Link to comment
Share on other sites

Hi HA!*!*Y

 

This solution has side effects:

 

All product metadata don't appearing and the title of page products show a default shop title.

 

You can fix this?, apart from this problem everything works fine

 

Thanks

 

Rysiu

Link to comment
Share on other sites

FREE module available now:

http://www.prestashop.com/forums/index.php?/topic/110922-friendly-urls-without-id-number/page__view__findpost__p__883380

 

i am look into it right now

 

this is a temporary solutions to the problem

 

Add this at the end of file: ./config/config.inc.php

 //remove link id by Ha!*!*y
 if (Tools::getValue('product_name_seo'))
 {
  $id_product = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('
	SELECT `id_product`
	FROM `'._DB_PREFIX_.'product_lang`
	WHERE `link_rewrite` = \''.Tools::getValue('product_name_seo').'\'');
  $_GET['id_product'] = $id_product;
 }

Edited by HA!*!*Y (see edit history)
  • Like 1
Link to comment
Share on other sites

  • 2 weeks later...

Works partially on my 1.4.5... It does remove the ID from products, but not from my categories and neither CMS links.. Any idea why ?? however it did the most important thing... remove the ID from products.. Thanks.

Link to comment
Share on other sites

  • 2 weeks later...

FREE module available now:

http://www.prestashop.com/forums/index.php?/topic/110922-friendly-urls-without-id-number/page__view__findpost__p__883380

 

This also worked partially for me.

 

It removes the ID's from product URL's, but it doesn't update all my URL's automatically, so all my links to products are broken.

 

Do I need to do something to my htaccess file to do that?

 

Yes Go to:

Back Office > Tools > Generators

 

Generate your ".htaccess" file by clicking the button

Edited by HA!*!*Y (see edit history)
Link to comment
Share on other sites

FREE module available now:

http://www.prestashop.com/forums/index.php?/topic/110922-friendly-urls-without-id-number/page__view__findpost__p__883380

 

Works partially on my 1.4.5... It does remove the ID from products, but not from my categories and neither CMS links.. Any idea why ?? however it did the most important thing... remove the ID from products.. Thanks.

 

C.Perez, i did not update the code to remove IDs from categories or CMS link ill try to post that some time

Edited by HA!*!*Y (see edit history)
Link to comment
Share on other sites

Yes Go to:

Back Office > Tools > Generators

 

Generate your ".htaccess" file by clicking the button

 

Thanks for your reply HA!*!*Y.

 

I did try regenerating my htaccess file from the back-office, but it didn't work.

 

Could that be due to permissions on the file on the server? If I CHMOD the htaccess file to 777 will that work?

Link to comment
Share on other sites

  • 2 weeks later...

Is there any progress in getting this to work for categories and subcategories? I had a bash at it myself, using your amends as a basis but unfortunately my dev skills don't seem up to the job as it didn't work! I edited the Link.php, Tools.php and config file but wasn't sure if anything needed changing in the ProductController, so perhaps that's where the issue lies...

 

edit - Just realised it's the CategoryController file that needs editing, not ProductController of course. Unfortunately still not working so must be missing something?

Edited by emma_w (see edit history)
Link to comment
Share on other sites

  • 2 weeks later...

FREE module available now:

http://www.prestashop.com/forums/index.php?/topic/110922-friendly-urls-without-id-number/page__view__findpost__p__883380

 

 

To remove number from Category URL

 

1st file: ./controllers/CategoryController.php

 

update the function preProcess()

public function preProcess()
{
	if ($id_category = (int)Tools::getValue('id_category'))
		{ $this->category = new Category($id_category, self::$cookie->id_lang); }
	else //remove link id by Ha!*!*y
	{
		$id_category = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('
			SELECT `link_rewrite`
			FROM `'._DB_PREFIX_.'category_lang`
			WHERE `link_rewrite` = \''.Tools::getValue('category_name_seo').'\'');
		$this->category = new Category($id_category, self::$cookie->id_lang);
	} //remove link id by Ha!*!*y
....

 

2nd file: ./classes/Link.php

 

update the function getCategoryLink

I removed (int)($id_category->id).'-'. from the functions in 2 places

 

public function getCategoryLink($id_category, $alias = NULL, $id_lang = NULL)
{
 if (is_object($id_category))
  return ($this->allow == 1) ? (_PS_BASE_URL_.__PS_BASE_URI__.$this->getLangLink((int)($id_lang)).$id_category->link_rewrite) :
  (_PS_BASE_URL_.__PS_BASE_URI__.'category.php?id_category='.(int)($id_category->id));
 if ($alias)
  return ($this->allow == 1) ? (_PS_BASE_URL_.__PS_BASE_URI__.$this->getLangLink((int)($id_lang)).$alias) :
  (_PS_BASE_URL_.__PS_BASE_URI__.'category.php?id_category='.(int)($id_category));
 return _PS_BASE_URL_.__PS_BASE_URI__.'category.php?id_category='.(int)($id_category);
}

 

3rd file: ./classes/Tools.php

 

update the function generateHtaccess()

 

find inside the function

 if ($multilang)
 {
.....
....
   	 $tab['RewriteRule']['content']['^([a-z]{2})/([0-9]+)\-[a-zA-Z0-9-]*(/[a-zA-Z0-9-]*)+'] = 'category.php?id_category=$2&isolang=$1&noredirect=1 [QSA,L]';
		$tab['RewriteRule']['content']['^([a-z]{2})/([0-9]+)\-[a-zA-Z0-9-]*'] = 'category.php?id_category=$2&isolang=$1 [QSA,L]';
....
....

 

Add the following lines:

//remove link id by Ha!*!*y
		$tab['RewriteEngine']['content_no_id'][] = 'RewriteCond %{REQUEST_FILENAME} !-f';
		$tab['RewriteEngine']['content_no_id'][] = 'RewriteCond %{REQUEST_FILENAME} !-d';
		$tab['RewriteEngine']['content_no_id'][] = 'RewriteRule ^([a-z]{2})/([a-zA-Z0-9-])(/[a-zA-Z0-9-]*)+ category.php?category_name_seo=$2&isolang=$1&noredirect=1 [QSA,L]';
		$tab['RewriteEngine']['content_no_id'][] = 'RewriteCond %{REQUEST_FILENAME} !-f';
		$tab['RewriteEngine']['content_no_id'][] = 'RewriteCond %{REQUEST_FILENAME} !-d';
		$tab['RewriteEngine']['content_no_id'][] = 'RewriteRule ^([a-z]{2})/([a-zA-Z0-9-]*) category.php?category_name_seo=$2&isolang=$1&noredirect=1 [QSA,L]';
//remove link id by Ha!*!*y

 

Find

 // Notice : the id_category rule has to be after product rules.
 // If not, category with number in their name will result a bug
 $tab['RewriteRule']['content']['^([0-9]+)\-[a-zA-Z0-9-]*(/[a-zA-Z0-9-]*)+'] = 'category.php?id_category=$1&noredirect=1 [QSA,L]';
 $tab['RewriteRule']['content']['^([0-9]+)\-[a-zA-Z0-9-]*'] = 'category.php?id_category=$1 [QSA,L]';

 

Add the following lines:

//remove link id by Ha!*!*y
		$tab['RewriteEngine']['content_no_id'][] = 'RewriteCond %{REQUEST_FILENAME} !-f';
		$tab['RewriteEngine']['content_no_id'][] = 'RewriteCond %{REQUEST_FILENAME} !-d';
		$tab['RewriteEngine']['content_no_id'][] = 'RewriteRule ^([a-zA-Z0-9-]*)(/[a-zA-Z0-9-]*) category.php?category_name_seo=$1&noredirect=1 [QSA,L]';
		$tab['RewriteEngine']['content_no_id'][] = 'RewriteCond %{REQUEST_FILENAME} !-f';
		$tab['RewriteEngine']['content_no_id'][] = 'RewriteCond %{REQUEST_FILENAME} !-d';
		$tab['RewriteEngine']['content_no_id'][] = 'RewriteRule ^([a-zA-Z0-9-]*) category.php?category_name_seo=$1 [QSA,L]';
//remove link id by Ha!*!*y

 

Add this at the end of file: ./config/config.inc.php

 //remove link id by Ha!*!*y
 if (Tools::getValue('product_name_seo'))
 {
  $id_product = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('
		SELECT `id_product`
		FROM `'._DB_PREFIX_.'product_lang`
		WHERE `link_rewrite` = \''.Tools::getValue('product_name_seo').'\'');
  $_GET['id_product'] = $id_product;
 }

Than Go to:

Back Office > Tools > Generators

 

Generate your ".htaccess" file by clicking the button

Edited by HA!*!*Y (see edit history)
  • Like 1
Link to comment
Share on other sites

Brilliant, thanks for this. I will try this out as soon as I get the chance. I'm interested to see what bit of code I got wrong when trying it myself (probably the htaccess file - I must admit I don't quite understand all the rewrite code).

Link to comment
Share on other sites

if you find that there is an error with the category id

There is 1 error :

Missing category ID

 

you will have to do the fallowing

 

Change in /classes/Tools.php (just remove the "+" sign before the filename)

FROM

 

//remove link id by Ha!*!*y

$tab['RewriteEngine']['content_no_id'][] = 'RewriteCond %{REQUEST_FILENAME} !-f';

$tab['RewriteEngine']['content_no_id'][] = 'RewriteCond %{REQUEST_FILENAME} !-d';

$tab['RewriteEngine']['content_no_id'][] = 'RewriteRule ^([a-zA-Z0-9-]*)(/[a-zA-Z0-9-]*)+ category.php?category_name_seo=$1&noredirect=1 [QSA,L]';

$tab['RewriteEngine']['content_no_id'][] = 'RewriteCond %{REQUEST_FILENAME} !-f';

$tab['RewriteEngine']['content_no_id'][] = 'RewriteCond %{REQUEST_FILENAME} !-d';

$tab['RewriteEngine']['content_no_id'][] = 'RewriteRule ^([a-zA-Z0-9-]*)+ category.php?category_name_seo=$1 [QSA,L]';

//remove link id by Ha!*!*y

TO

 

 

//remove link id by Ha!*!*y

$tab['RewriteEngine']['content_no_id'][] = 'RewriteCond %{REQUEST_FILENAME} !-f';

$tab['RewriteEngine']['content_no_id'][] = 'RewriteCond %{REQUEST_FILENAME} !-d';

$tab['RewriteEngine']['content_no_id'][] = 'RewriteRule ^([a-zA-Z0-9-]*)(/[a-zA-Z0-9-]*) category.php?category_name_seo=$1&noredirect=1 [QSA,L]';

$tab['RewriteEngine']['content_no_id'][] = 'RewriteCond %{REQUEST_FILENAME} !-f';

$tab['RewriteEngine']['content_no_id'][] = 'RewriteCond %{REQUEST_FILENAME} !-d';

$tab['RewriteEngine']['content_no_id'][] = 'RewriteRule ^([a-zA-Z0-9-]*) category.php?category_name_seo=$1 [QSA,L]';

//remove link id by Ha!*!*y

 

Add at the end of /config/config.inc.php

 

if (Tools::getValue('category_name_seo'))

{

$id_category = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('

SELECT `id_category`

FROM `'._DB_PREFIX_.'category_lang`

WHERE `link_rewrite` = \''.Tools::getValue('category_name_seo').'\'');

$_GET['id_category'] = $id_category;

}

 

 

and regenerate you htaccess

  • Like 2
Link to comment
Share on other sites

please I have 1.4.8.2 I tried to modify that file, but I do wrong some code, if I use file modified by me it doesn't work (500 error), please could you give to me file right for that version of ps?

Thanks

Link to comment
Share on other sites

Have you modified ALL the files necessary?

 

./controllers/ProductController.php

./controllers/CategoryController.php

./classes/Link.php

./classes/Tools.php

./config/config.inc.php

 

..AND generated a new htaccess file through your admin?

Link to comment
Share on other sites

Hello, I am writing you because I had changed the URL of the items will be displayed without the category.

 

Ex. www.web.com/5-category/124-product.html to www.web.com/124-product.html

 

This I have taken from this post: http://www.prestashop.com/forums/topic/30419-remove-category-from-product-url/

 

When I apply the changes that you have indicated the URL shown without ID but instead the categories reappear in the URL.

 

I would like this: www.web.com/product.html

 

Someone could help me fix this?

 

Thanks!

Link to comment
Share on other sites

FREE module available now:

http://www.prestashop.com/forums/index.php?/topic/110922-friendly-urls-without-id-number/page__view__findpost__p__883380

 

Hello, I am writing you because I had changed the URL of the items will be displayed without the category.

 

Ex. www.web.com/5-category/124-product.html to www.web.com/124-product.html

 

This I have taken from this post: http://www.prestasho...om-product-url/

 

When I apply the changes that you have indicated the URL shown without ID but instead the categories reappear in the URL.

 

I would like this: www.web.com/product.html

 

Someone could help me fix this?

 

Thanks!

 

antonpas_bcn

if all you want to do is remove the category name from URL its really easy

 

go to file ./classes/Link.php and find public function getProductLink

and edit out the line from

 

if (isset($id_product->category) AND !empty($id_product->category) AND $id_product->category != 'home')
 $link .= $id_product->category.'/';

 

TO

if (isset($id_product->category) AND !empty($id_product->category) AND $id_product->category != 'home')
 $link .= '';

 

 

AND ALSO

$link .= (_PS_BASE_URL_.__PS_BASE_URI__.$this->getLangLink((int)$id_lang));

if ($category AND $category != 'home')
 $link .= $category.'/';

 

TO

$link .= (_PS_BASE_URL_.__PS_BASE_URI__.$this->getLangLink((int)$id_lang));

if ($category AND $category != 'home')
 $link .= '';

Edited by HA!*!*Y (see edit history)
Link to comment
Share on other sites

Thank you for this solution. I want to ask what kind of side effects can be occur by doing these changes. İnitially I think about:

 

1-Duplicate url - Canonical url problems

2-Speed and performance problems

3-Core function or module problem

 

What kind of undesirable effects can be come out when we do this changes? Or isn't there any problem or negative effects?

  • Like 1
Link to comment
Share on other sites

Kerym there are some negative effects from it

1. Duplicate urls if you create two Products with the same seo url than prestashop will redirect you the the 1st of the 2 urls

 

2. if you keep the ID in the URL than you could change the SEO URL and the old URLS will 301 redirect to the new address

----- old url: www.web.com/category/124-product.html

----- new url: www.web.com/category/124-new-seo-url.html

 

3. As long as the modules use the getProductLink() function for the URLs there should not be any issues from it.

 

4. And far as performances go i don't see any slow down

  • Like 1
Link to comment
Share on other sites

To remove number from Category URL

 

1st file: ./controllers/CategoryController.php

 

update the function preProcess()

public function preProcess()
{
	if ($id_category = (int)Tools::getValue('id_category'))
		{ $this->category = new Category($id_category, self::$cookie->id_lang); }
	else //remove link id by Ha!*!*y
	{
		$id_category = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('
			SELECT `link_rewrite`
			FROM `'._DB_PREFIX_.'category_lang`
			WHERE `link_rewrite` = \''.Tools::getValue('category_name_seo').'\'');
		$this->category = new Category($id_category, self::$cookie->id_lang);
	} //remove link id by Ha!*!*y
....

 

2nd file: ./classes/Link.php

 

update the function getCategoryLink

I removed (int)($id_category->id).'-'. from the functions in 2 places

 

public function getCategoryLink($id_category, $alias = NULL, $id_lang = NULL)
{
 if (is_object($id_category))
  return ($this->allow == 1) ? (_PS_BASE_URL_.__PS_BASE_URI__.$this->getLangLink((int)($id_lang)).$id_category->link_rewrite) :
  (_PS_BASE_URL_.__PS_BASE_URI__.'category.php?id_category='.(int)($id_category->id));
 if ($alias)
  return ($this->allow == 1) ? (_PS_BASE_URL_.__PS_BASE_URI__.$this->getLangLink((int)($id_lang)).$alias) :
  (_PS_BASE_URL_.__PS_BASE_URI__.'category.php?id_category='.(int)($id_category));
 return _PS_BASE_URL_.__PS_BASE_URI__.'category.php?id_category='.(int)($id_category);
}

 

3rd file: ./classes/Tools.php

 

update the function generateHtaccess()

 

find inside the function

 if ($multilang)
 {
.....
....
   	 $tab['RewriteRule']['content']['^([a-z]{2})/([0-9]+)\-[a-zA-Z0-9-]*(/[a-zA-Z0-9-]*)+'] = 'category.php?id_category=$2&isolang=$1&noredirect=1 [QSA,L]';
		$tab['RewriteRule']['content']['^([a-z]{2})/([0-9]+)\-[a-zA-Z0-9-]*'] = 'category.php?id_category=$2&isolang=$1 [QSA,L]';
....
....

 

Add the following lines:

//remove link id by Ha!*!*y
		$tab['RewriteEngine']['content_no_id'][] = 'RewriteCond %{REQUEST_FILENAME} !-f';
		$tab['RewriteEngine']['content_no_id'][] = 'RewriteCond %{REQUEST_FILENAME} !-d';
		$tab['RewriteEngine']['content_no_id'][] = 'RewriteRule ^([a-z]{2})/([a-zA-Z0-9-])(/[a-zA-Z0-9-]*)+ category.php?category_name_seo=$2&isolang=$1&noredirect=1 [QSA,L]';
		$tab['RewriteEngine']['content_no_id'][] = 'RewriteCond %{REQUEST_FILENAME} !-f';
		$tab['RewriteEngine']['content_no_id'][] = 'RewriteCond %{REQUEST_FILENAME} !-d';
		$tab['RewriteEngine']['content_no_id'][] = 'RewriteRule ^([a-z]{2})/([a-zA-Z0-9-]*) category.php?category_name_seo=$2&isolang=$1&noredirect=1 [QSA,L]';
//remove link id by Ha!*!*y

 

Find

 // Notice : the id_category rule has to be after product rules.
 // If not, category with number in their name will result a bug
 $tab['RewriteRule']['content']['^([0-9]+)\-[a-zA-Z0-9-]*(/[a-zA-Z0-9-]*)+'] = 'category.php?id_category=$1&noredirect=1 [QSA,L]';
 $tab['RewriteRule']['content']['^([0-9]+)\-[a-zA-Z0-9-]*'] = 'category.php?id_category=$1 [QSA,L]';

 

Add the following lines:

//remove link id by Ha!*!*y
		$tab['RewriteEngine']['content_no_id'][] = 'RewriteCond %{REQUEST_FILENAME} !-f';
		$tab['RewriteEngine']['content_no_id'][] = 'RewriteCond %{REQUEST_FILENAME} !-d';
		$tab['RewriteEngine']['content_no_id'][] = 'RewriteRule ^([a-zA-Z0-9-]*)(/[a-zA-Z0-9-]*) category.php?category_name_seo=$1&noredirect=1 [QSA,L]';
		$tab['RewriteEngine']['content_no_id'][] = 'RewriteCond %{REQUEST_FILENAME} !-f';
		$tab['RewriteEngine']['content_no_id'][] = 'RewriteCond %{REQUEST_FILENAME} !-d';
		$tab['RewriteEngine']['content_no_id'][] = 'RewriteRule ^([a-zA-Z0-9-]*) category.php?category_name_seo=$1 [QSA,L]';
//remove link id by Ha!*!*y

 

Add this at the end of file: ./config/config.inc.php

 //remove link id by Ha!*!*y
 if (Tools::getValue('product_name_seo'))
 {
  $id_product = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('
		SELECT `id_product`
		FROM `'._DB_PREFIX_.'product_lang`
		WHERE `link_rewrite` = \''.Tools::getValue('product_name_seo').'\'');
  $_GET['id_product'] = $id_product;
 }

Than Go to:

Back Office > Tools > Generators

 

Generate your ".htaccess" file by clicking the button

 

Hi! HA!*!*Y

I am stuck with Your tutorial an I get only blank page :(

I have prestashop 1.4.8.2

 

Best Regards

Raitis

Link to comment
Share on other sites

Thank you for detailed answers HA!*!*Y you are great.

 

Prestashoponline what is the difference of your module? What kind of benefits does your module have more than HA!*!*Y's solution on deleting id from urls?

 

Thanks

Link to comment
Share on other sites

prestashoponline's module is for money ... this is the diference...

 

This module has also been reported for potentially being stolen content. Please do not purchase it until this has been resolved.

 

Thank you for detailed answers HA!*!*Y you are great.

 

Prestashoponline what is the difference of your module? What kind of benefits does your module have more than HA!*!*Y's solution on deleting id from urls?

 

Thanks

 

Please do not purchase this module. It has been reported as potential stolen content. We are investigating.

Link to comment
Share on other sites

I am moving to a new post for updates see URL:

 

http://www.prestasho...hout-id-number/

 

 

No more file editing i have a free module

 

did not fix the cms links as of now

 

plz note its a bata need to be tested

 

change log (removeURLid_v0.1b.2.zip)

- fixed name typo (capital class name) that caused problem with installing

 

change log (removeURLid_v0.1b.1.zip)

-fixed the CategoryController file path by corint1

-module now edits the config file

 

change log (removeURLid_v0.1b.1.zip)

- 1st release

removeURLid_v0.1b.zip

removeURLid_v0.1b.1.zip

removeURLid_v0.1b.2.zip

Edited by HA!*!*Y (see edit history)
  • Like 4
Link to comment
Share on other sites

working perfect...but must modify lines :

 

'CategoryController' => _PS_ROOT_DIR_ . $slash . '/override/classes/Tools.php',

to

'CategoryController' => _PS_ROOT_DIR_ . $slash . '/override/classes/CategoryController.php',

 

in all 3 places ...

 

tks ...

 

read all specification or search in files for explication ....

//Edit the conf file??

//config.inc.php

isn't possible to append ? or create o new file and copy like other files ...

 

problem is with install ... if need cu override other procedures in this files , when installing this module lost all modification (copy new files, not append modifications)...same problem is on uninstall...backup not working ... append is a solution ... is possible ? same problem in on uninstall...

Edited by corint1 (see edit history)
Link to comment
Share on other sites

  • 3 weeks later...

How to remove ID from CMS Page

1./ Open /controllers/CMSController.php

Find:

if ($id_cms = (int)Tools::getValue('id_cms'))

Replace With:

if ($id_cms = (int)Tools::getValue('id_cms') and $id_cms != 0)

 

 

2./ Open /classes/Link.php

Find:

public function getCMSCategoryLink

Replace function with:

public function getCMSCategoryLink($id_category, $alias = NULL, $id_lang = NULL)

{

if (is_object($id_category))

return ($this->allow == 1) ? (_PS_BASE_URL_.__PS_BASE_URI__.$this->getLangLink((int)($id_lang)).'content/category/'.$id_category->link_rewrite) :

(_PS_BASE_URL_.__PS_BASE_URI__.'cms.php?id_cms_category='.(int)($id_category->id));

if ($alias)

return ($this->allow == 1) ? (_PS_BASE_URL_.__PS_BASE_URI__.$this->getLangLink((int)($id_lang)).'content/category/'.$alias) :

(_PS_BASE_URL_.__PS_BASE_URI__.'cms.php?id_cms_category='.(int)($id_category));

return _PS_BASE_URL_.__PS_BASE_URI__.'cms.php?id_cms_category='.(int)($id_category);

}

Find:

public function getCMSLink

Replace with:

 

public function getCMSLink($cms, $alias = null, $ssl = false, $id_lang = NULL)

{

$base = (($ssl AND Configuration::get('PS_SSL_ENABLED')) ? Tools::getShopDomainSsl(true) : Tools::getShopDomain(true));

 

if (is_object($cms))

{

return ($this->allow == 1) ?

($base.__PS_BASE_URI__.$this->getLangLink((int)($id_lang)).'content/'.$cms->link_rewrite) :

($base.__PS_BASE_URI__.'cms.php?id_cms='.(int)($cms->id));

}

 

if ($alias)

return ($this->allow == 1) ? ($base.__PS_BASE_URI__.$this->getLangLink((int)($id_lang)).'content/'.$alias) :

($base.__PS_BASE_URI__.'cms.php?id_cms='.(int)($cms));

return $base.__PS_BASE_URI__.'cms.php?id_cms='.(int)($cms);

}

 

 

3./ Open /classes/Tools.php

Search for

public static function generateHtaccess(

Find inside this function:

 

if ($multilang)

{

 

Add inside this clause (if you used Ha!*!*y method for categories the add above this conditions the fallowing lines)

 

$tab['RewriteEngine']['content_no_id'][] = 'RewriteCond %{REQUEST_FILENAME} !-f';

$tab['RewriteEngine']['content_no_id'][] = 'RewriteCond %{REQUEST_FILENAME} !-d';

$tab['RewriteEngine']['content_no_id'][] = 'RewriteRule ^([a-z]{2})/content/category/([a-zA-Z0-9-]*) cms.php?cms_category_name_seo=$1&noredirect=1 [QSA,L]';

$tab['RewriteEngine']['content_no_id'][] = 'RewriteCond %{REQUEST_FILENAME} !-f';

$tab['RewriteEngine']['content_no_id'][] = 'RewriteCond %{REQUEST_FILENAME} !-d';

$tab['RewriteEngine']['content_no_id'][] = 'RewriteRule ^([a-z]{2})/content/([a-zA-Z0-9-]*) cms.php?cms_name_seo=$1 [QSA,L]';

 

 

After the if clause and above(if you used Ha!*!*y method for categories the add above this conditions the fallowing lines) add

 

 

$tab['RewriteEngine']['content_no_id'][] = 'RewriteCond %{REQUEST_FILENAME} !-f';

$tab['RewriteEngine']['content_no_id'][] = 'RewriteCond %{REQUEST_FILENAME} !-d';

$tab['RewriteEngine']['content_no_id'][] = 'RewriteRule ^content/category/([a-zA-Z0-9-]*) cms.php?cms_category_name_seo=$1&noredirect=1 [QSA,L]';

$tab['RewriteEngine']['content_no_id'][] = 'RewriteCond %{REQUEST_FILENAME} !-f';

$tab['RewriteEngine']['content_no_id'][] = 'RewriteCond %{REQUEST_FILENAME} !-d';

$tab['RewriteEngine']['content_no_id'][] = 'RewriteRule ^content/([a-zA-Z0-9-]*) cms.php?cms_name_seo=$1 [QSA,L]';

 

 

4./ Open /config/config.inc.php

append at the end of the file the fallowing

// Cms Category

if (Tools::getValue('cms_category_name_seo'))

{

$id_category = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('

SELECT `id_cms_category`

FROM `'._DB_PREFIX_.'cms_category_lang`

WHERE `link_rewrite` = \''.Tools::getValue('cms_category_name_seo').'\'');

$_GET['id_cms_category'] = $id_category;

}

// Cms Page

if (Tools::getValue('cms_name_seo')) {

$id_cms = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('

SELECT `id_cms`

FROM `'._DB_PREFIX_.'cms_lang`

WHERE `link_rewrite` = \''.Tools::getValue('cms_name_seo').'\'');

$_GET['id_cms'] = $id_cms;

}

 

REGENERATE YOU HTACCESS

 

I don't have enoght patience to explain this more clear, thus I ask the users reading this forum to make a more detailed explication.

Ha!*!*y - Please implement this functionality in your module and make it public to the word!

Live Free - Live Strong

Edited by ODM (see edit history)
  • Like 2
Link to comment
Share on other sites

The same principle that Ha!*!*y started applies for ALL URL's. The only remaining ones are for Manufacturers and Vendors.

I have applied it for CMS pages (because this was asked by a client for one of my projects) If in the future projects I will require to remove the ID for manufacturers and/or vendors I will do it and post it here :)

 

 

 

PS1 It toked me 5 minutes to remove the ID .... All the files where the url functions are located are listed above, and it's pretty simple even for a "PrestaShop Apprentice" :)

 

PS2 I hope that Prestashop Dev Team has in mind the removal of IDs from all urls in the final version of 1.5 :)

Link to comment
Share on other sites

  • 2 weeks later...

Hello duxyz,

 

Welcome to the PrestaShop Forums! We are very glad to have you with us. If you do not mind, please specify which error you receive. Also, if you could please post screenshots, this will help us too. Thank you so much for using PrestaShop.

 

Hi, Benjamin. Thank you for being so kind! :)

 

When I clicked on uninstall i got red error message that it can't be installed successfully. I know, it said "installed", not "uninstalled".

After that it was showing in modules that it really is not installed, but some of the links on the page were still "friendly" and pages were acting strange. I checked .htaccess and the "friendly" code really was removed. I don't understand the problem.

 

I decided than to try install it again, because it was working OK while installed. My site works perfectly now. I just wanted to remove it because some of my old links were already indexed in Google before installing this module, but never mind, Google will index new ones soon.

I am just hoping that this cool module will work on new versions of Prestashop, so I don't loose newly indexed friendly links! (they are really so cool without those unnecessary numbers! :))

 

p.s. I hope you understood me, because my English sucks!

Link to comment
Share on other sites

  • 3 weeks later...

Hi all,

 

great module! Works great.

 

However I got two questions regarding this.

 

First off I think I broke something when I installed this as date and time won't show in carts and orders, see pictures. The date and time is visible when u click a specific cart or order though. Also a lot of information seems to be missing in the order details. Any idea how to fix this?

 

EJHym.png

 

Tl8d2.png

 

Also in the theme of the thread. An1 could tell me how to remove the .html for all product pages. So it just says productname...?

Edited by benknackan (see edit history)
Link to comment
Share on other sites

No more file editing i have a free module

 

did not fix the cms links as of now

 

plz note its a bata need to be tested

 

change log (removeURLid_v0.1b.2.zip)

- fixed name typo (capital class name) that caused problem with installing

 

change log (removeURLid_v0.1b.1.zip)

-fixed the CategoryController file path by corint1

-module now edits the config file

 

change log (removeURLid_v0.1b.1.zip)

- 1st release

 

 

hi, actually I'm installed in my shop and works well, now I want to upgrade my shop to PS 1.5 can you tellme if it works on PS1.5

thankyou!

Link to comment
Share on other sites

I installed HA!*!*Y module removeURLid_v0.1b.2.zip which works flawlessly for products and categories.

 

I also followed ODM's instructions on "How to Remove ID from CMS Page" but still couldn't get CMS pages to work without IDs.

 

The IDs still show on CMS menu links. When manually removing the IDs in the URL, I get the following error:

 

There is 1 error :

  • Missing category ID

Am I missing something here?

Link to comment
Share on other sites

I think those instructions by OEM to remove ID# from CMS pages may have some problems because a few of us have problems getting it to work. In the meantime, if you just want no ID # for products, just install the HA!*!*Y module removeURLid_v0.1b.2.zip and that should work with no problems.

 

Hi guys, this is a Prestashop newbie on his first message.

I tried to follow the steps, but now I'm getting a blank product description page in every product detail. Since my knowledge as developer is very basic, I wouldn't mind of going back to the beginning and forget about deleting category and product ID's. But I don't know how.

- I tried to restore previous backups, when I didn't have this problem, but the problem doesn't solve.

- I also tried restoring the original files from prestashop 1.4.9 that I modified following the steps of this post (productcontroller.php, categorycontroller.php, link.php, tools.php and config.inc.php) but the page keeps being in blank.

Please let me know any solution in order to fix this problem.

Thank you all so much.

Ivon

 

Ps. I would give you additional information of the site if asked. Attaching a couple of escreenshots.

Link to comment
Share on other sites

I think those instructions by OEM to remove ID# from CMS pages may have some problems because a few of us have problems getting it to work. In the meantime, if you just want no ID # for products, just install the HA!*!*Y module removeURLid_v0.1b.2.zip and that should work with no problems.

 

Looks like my problem was with another module. Sorry and thanks all.

Edited by loraleku.com (see edit history)
Link to comment
Share on other sites

  • 1 month later...

Hello,

 

i have problem with friendly urls in category.

I have PS 1.4.4.1

 

I made exactly the same as below:

 

FREE module available now:

http://www.prestasho...post__p__883380

 

 

To remove number from Category URL

 

1st file: ./controllers/CategoryController.php

 

update the function preProcess()

public function preProcess()
{
	if ($id_category = (int)Tools::getValue('id_category'))
		{ $this->category = new Category($id_category, self::$cookie->id_lang); }
	else //remove link id by Ha!*!*y
	{
		$id_category = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('
			SELECT `link_rewrite`
			FROM `'._DB_PREFIX_.'category_lang`
			WHERE `link_rewrite` = \''.Tools::getValue('category_name_seo').'\'');
		$this->category = new Category($id_category, self::$cookie->id_lang);
	} //remove link id by Ha!*!*y
....

 

2nd file: ./classes/Link.php

 

update the function getCategoryLink

I removed (int)($id_category->id).'-'. from the functions in 2 places

 

public function getCategoryLink($id_category, $alias = NULL, $id_lang = NULL)
{
 if (is_object($id_category))
  return ($this->allow == 1) ? (_PS_BASE_URL_.__PS_BASE_URI__.$this->getLangLink((int)($id_lang)).$id_category->link_rewrite) :
  (_PS_BASE_URL_.__PS_BASE_URI__.'category.php?id_category='.(int)($id_category->id));
 if ($alias)
  return ($this->allow == 1) ? (_PS_BASE_URL_.__PS_BASE_URI__.$this->getLangLink((int)($id_lang)).$alias) :
  (_PS_BASE_URL_.__PS_BASE_URI__.'category.php?id_category='.(int)($id_category));
 return _PS_BASE_URL_.__PS_BASE_URI__.'category.php?id_category='.(int)($id_category);
}

 

3rd file: ./classes/Tools.php

 

update the function generateHtaccess()

 

find inside the function

 if ($multilang)
 {
.....
....
   	 $tab['RewriteRule']['content']['^([a-z]{2})/([0-9]+)\-[a-zA-Z0-9-]*(/[a-zA-Z0-9-]*)+'] = 'category.php?id_category=$2&isolang=$1&noredirect=1 [QSA,L]';
		$tab['RewriteRule']['content']['^([a-z]{2})/([0-9]+)\-[a-zA-Z0-9-]*'] = 'category.php?id_category=$2&isolang=$1 [QSA,L]';
....
....

 

Add the following lines:

//remove link id by Ha!*!*y
		$tab['RewriteEngine']['content_no_id'][] = 'RewriteCond %{REQUEST_FILENAME} !-f';
		$tab['RewriteEngine']['content_no_id'][] = 'RewriteCond %{REQUEST_FILENAME} !-d';
		$tab['RewriteEngine']['content_no_id'][] = 'RewriteRule ^([a-z]{2})/([a-zA-Z0-9-])(/[a-zA-Z0-9-]*)+ category.php?category_name_seo=$2&isolang=$1&noredirect=1 [QSA,L]';
		$tab['RewriteEngine']['content_no_id'][] = 'RewriteCond %{REQUEST_FILENAME} !-f';
		$tab['RewriteEngine']['content_no_id'][] = 'RewriteCond %{REQUEST_FILENAME} !-d';
		$tab['RewriteEngine']['content_no_id'][] = 'RewriteRule ^([a-z]{2})/([a-zA-Z0-9-]*) category.php?category_name_seo=$2&isolang=$1&noredirect=1 [QSA,L]';
//remove link id by Ha!*!*y

 

Find

 // Notice : the id_category rule has to be after product rules.
 // If not, category with number in their name will result a bug
 $tab['RewriteRule']['content']['^([0-9]+)\-[a-zA-Z0-9-]*(/[a-zA-Z0-9-]*)+'] = 'category.php?id_category=$1&noredirect=1 [QSA,L]';
 $tab['RewriteRule']['content']['^([0-9]+)\-[a-zA-Z0-9-]*'] = 'category.php?id_category=$1 [QSA,L]';

 

Add the following lines:

//remove link id by Ha!*!*y
		$tab['RewriteEngine']['content_no_id'][] = 'RewriteCond %{REQUEST_FILENAME} !-f';
		$tab['RewriteEngine']['content_no_id'][] = 'RewriteCond %{REQUEST_FILENAME} !-d';
		$tab['RewriteEngine']['content_no_id'][] = 'RewriteRule ^([a-zA-Z0-9-]*)(/[a-zA-Z0-9-]*) category.php?category_name_seo=$1&noredirect=1 [QSA,L]';
		$tab['RewriteEngine']['content_no_id'][] = 'RewriteCond %{REQUEST_FILENAME} !-f';
		$tab['RewriteEngine']['content_no_id'][] = 'RewriteCond %{REQUEST_FILENAME} !-d';
		$tab['RewriteEngine']['content_no_id'][] = 'RewriteRule ^([a-zA-Z0-9-]*) category.php?category_name_seo=$1 [QSA,L]';
//remove link id by Ha!*!*y

 

Add this at the end of file: ./config/config.inc.php

 //remove link id by Ha!*!*y
 if (Tools::getValue('product_name_seo'))
 {
  $id_product = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('
		SELECT `id_product`
		FROM `'._DB_PREFIX_.'product_lang`
		WHERE `link_rewrite` = \''.Tools::getValue('product_name_seo').'\'');
  $_GET['id_product'] = $id_product;
 }

Than Go to:

Back Office > Tools > Generators

 

Generate your ".htaccess" file by clicking the button

 

 

.. and does not work.

 

I have category url: /8-uslugi

When i do: /uslugi

 

I've done everything as above

and i see: page not found

 

When I did the friendly url for products it all works.

 

PLEASE HELP!

 

_____________________________

 

Agencja Reklamowa JUSTPRO

Edited by henryk20 (see edit history)
Link to comment
Share on other sites

But, I have another question. How to remove .html from product url?

 

I,ve tried to do this, but than I realized that this is zero sum game.

why?

because, if you are willing to spend from one to seven days for saving max 150$(this is the most expensive seo module) go ahead, if not, my suggestion is, buy seo module for presta. that is what I have done.

seo modules you can get from 40$-150$.

 

this is my opinion. you do as you think is best for you.

Link to comment
Share on other sites

I,ve tried to do this, but than I realized that this is zero sum game.

why?

because, if you are willing to spend from one to seven days for saving max 150$(this is the most expensive seo module) go ahead, if not, my suggestion is, buy seo module for presta. that is what I have done.

seo modules you can get from 40$-150$.

 

this is my opinion. you do as you think is best for you.

 

Thanks for Your answer.

 

Now for me the best solution is to remove .html from url.

Anyone did this?

 

_____________________________

 

Agencja Reklamowa JUSTPRO

Edited by henryk20 (see edit history)
Link to comment
Share on other sites

  • 2 months later...

Anyone an idea how to use capital letters in URL's in Presta's latest version 1.5.2?

 

If I add or change a product via catalog > products > edit > seo the capital letters are directly changed into lowercase in the field friendly URL, so can't put it in.

 

Very frustrating because I don't want to make handmade redirects for my old indexed URL's wich look like /Products-Tennis.html for example. Now I can only make /products-tennis.html.

 

Wich piece of script can I change? When I make a category in Presta then it does allow capital letters. So it has to be possible.

 

Thanks in advance!

Edited by robbie007 (see edit history)
Link to comment
Share on other sites

  • 1 month later...

Can somebody help me out,

 

I tried this module and it removed the ID`s....but as i`m on a zeus server I cannot generate the .htaccess file. Now I am getting broken links even after removing the module and replacing my classes, controller, config and tools files. I cant find any info on the zeus equivalent to the .htaccess script that would make this work so is there any way to revert back to including the ID in the URL? I`m not sure exactly what files this module has overridden but i`ve tried a fresh install of my site from a backup and it`s had no affect?!!!

Link to comment
Share on other sites