PrestaShop Forum

The best place in the world to ask questions about PrestaShop and get advice from our passionate community!

PrestaShop Forum

Jump to content

 

[Help] Remove Category ID from URL

25 replies to this topic
#1
servpro2

    PrestaShop Newbie

  • Members
  • Pip
  • 3 posts
Ok, I am trying to remove the category and product ID from the friendly urls. I have Friendly URLs enabled.

Right now:

http://www.mysite.com/3-computers

http://www.mysite.com/4-dell-lcd

I want it to be:

http://www.mysite.com/computers

http://www.mysite.com/lcds/dell-lcd

(LCDs is the category name and dell lcd is the product)

Can someone help me with this?

#2
Damien Metzger

    PrestaShop Fanatic

  • PrestaTeam
  • 1243 posts
There's only one clean way to do it: you have to put every single category link in your htaccess...

#3
servpro2

    PrestaShop Newbie

  • Members
  • Pip
  • 3 posts

From 1234422035:

There's only one clean way to do it: you have to put every single category link in your htaccess...


How would I do that? Can you give me a sample line?

Thanks

#4
Damien Metzger

    PrestaShop Fanatic

  • PrestaTeam
  • 1243 posts
Yop

RewriteRule ^computers$ category.php?id_category=3 [QSA,L,E]
RewriteRule ^lcds/dell-lcd$ category.php?id_category=4 [QSA,L,E]

#5
servpro2

    PrestaShop Newbie

  • Members
  • Pip
  • 3 posts
thanks alot.

Do I need to modify core files to update the linking? I got it to work, but the menu still links to the old way.

#6
Damien Metzger

    PrestaShop Fanatic

  • PrestaTeam
  • 1243 posts
The menu is a module, so you can just override the module template by copying /modules/blockcategories/*.tpl in /themes/yourtheme/modules/blockcategories/*.tpl and remove the id in the links.

#7
chuko

    PrestaShop Newbie

  • Members
  • Pip
  • 8 posts
Pierre-Yves wrote a nice solution. Thanks, Pierre-Yves! It is a hack in that it messes with the prestashop core files, but that's what one must do for now. There are some other issues you might run into.

There are three relevant files on the page:
1) The module that automatically sets up the .htaccess file - urlrewritingplus_1_2.zip
2) The modifications to link.php - be careful here as the attached file is for prestashop 1.0, not 1.1 - however, the additions to the file still work fine as written
3) There is also in the thread the module translated (mostly) into english

#8
sidro.ro

    PrestaShop Apprentice

  • Moderators
  • 294 posts
would you explain with more details how it's done ? i read that post but i;m not so good in french.
i tested but still no changes made. same as before.
prestashop v1.1

in blockcategories i can find that line which makes that change
www.sidro.ro now with v1.4.6.2 and a new look !

#9
chuko

    PrestaShop Newbie

  • Members
  • Pip
  • 8 posts
Some instructions in English for using the urlrewritingplus module.

1) Download the file urlrewritingplus_1_2.zip from the thread, and unzip to the main modules directory
2) Download urlrewritingplus.php from the fourth page. This is the same module translated to English. Replace the old urlrewritingplus.php in the modules/urlrewritingplus directory with this one.
3) Download link.php from the first page, but don't use this one directly. Instead,
4) Open up the file classes/link.php and replace the functions "public function getProductLink" and "public function getCategoryLink" with those same functions from the link.php file you downloaded.
5) Go into the admin panel. Under modules, install and configure urlrewritingplus to Create the Rules for all products and categories, and then to Generate the Rules. You might want to backup your .htaccess file before doing this.

Hope that's helpful!

#10
sidro.ro

    PrestaShop Apprentice

  • Moderators
  • 294 posts
Works on v1.1 final for products and categories but not for the cms !!! when clicking on about-us for exemple the page returns a error not found on server.

any solutions ?



Cheers and good luck !
www.sidro.ro now with v1.4.6.2 and a new look !

#11
chuko

    PrestaShop Newbie

  • Members
  • Pip
  • 8 posts
I haven't tried to change the url rewrite for anything but the products and categories, but I imagine that you could extend the solutions by modifying the getCMSLink function in link.php just as you modified getCategoryLink and getProductLink (except that it ought to be more simple) and adding a new button to the urlrewritingplus module to support CMS. Same goes for getSupplierLink, getManufacturerLink, and so on.

Let us know if you have some success extending it!

#12
chuko

    PrestaShop Newbie

  • Members
  • Pip
  • 8 posts
I didn't understand what you were asking the first time, but here's an actual answer. To fix the error on the cms links when using the urlrewritingplus module:

Go to the admin panel. Click on modules and configure for urlrewritingplus.
At the bottom you'll see "File. Htaccess default". Click on the text field to edit.
Add this line: RewriteRule ^content/([0-9]+)\-([a-zA-Z0-9-]*)(.*)$ cms.php?id_cms=$1 [QSA,L,E]
Click on the button, "Save the file content .htaccess default".
Click on "Generate Rules"

That should do it. It just gives you the normal Prestashop Friendly URLs for the cms, but it does work...

#13
sidro.ro

    PrestaShop Apprentice

  • Moderators
  • 294 posts
sorry to inform that it doesn't work that way. seems that i have to modify the link.php at the "public function getCMSLink"

with the standard modfication as you explain it to me works fine for products and categories.

but

when i click on a cms returns server error page not found on server or resticted.


i do not what to insert a new tab in the module.
i just want to make it work without errors.

cheers !
www.sidro.ro now with v1.4.6.2 and a new look !

#14
Paul Bogdan

    PrestaShop Apprentice

  • Members
  • PipPip
  • 27 posts

From 1234467183:

The menu is a module, so you can just override the module template by copying /modules/blockcategories/*.tpl in /themes/yourtheme/modules/blockcategories/*.tpl and remove the id in the links.


I don't know what you say 'couse in my case there's no modules folder in theme directory

I have the same issue with the category number, I don't found anything to remove that number.

I'm using prestashop 1.0

#15
Paul Bogdan

    PrestaShop Apprentice

  • Members
  • PipPip
  • 27 posts

From 1234424686:

thanks alot.

Do I need to modify core files to update the linking? I got it to work, but the menu still links to the old way.


did you fixed it? can you please explain what the procedure is?

thanks

#16
kreasta

    PrestaShop Apprentice

  • Members
  • PipPip
  • 44 posts
i'm interested also

#17
Sanis

    PrestaShop Apprentice

  • Members
  • PipPip
  • 65 posts
Iam rewriting urls manually while Pierre-Yves solution appears to be outdated.
I cant figure is how to remove id from tpl file as suggested below.

From 1234467183:

The menu is a module, so you can just override the module template by copying /modules/blockcategories/*.tpl in /themes/yourtheme/modules/blockcategories/*.tpl and remove the id in the links.

What would be required code modification?

#18
j_dk

    PrestaShop Newbie

  • Members
  • Pip
  • 16 posts
Any one found the solution?

#19
Clooner

    PrestaShop Newbie

  • Members
  • Pip
  • 3 posts
Does anyone have a solution already? I need really clean urls! I already found out that when I copy the prestashop generated .htaccess into the url rewriting plus module default .htacces textarea it works better.

#20
Masino Sinaga

    PrestaShop Apprentice

  • Members
  • PipPip
  • 180 posts

From 1271399425:

Any one found the solution?


Yes. Please check this article:
How to Remove Category ID from URL of PrestaShop version 1.2.5
Sincerely,
Masino Sinaga
Open Script Solution