How to remove the category id from the routes and keep only the category url segment?

Help for integrating the Laravel package
Forum rules
Always add your Laravel, Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
kdim95
Advanced
Posts: 195
Joined: 26 Aug 2022, 12:17

How to remove the category id from the routes and keep only the category url segment?

Post by kdim95 » 06 Sep 2022, 04:05

Laravel framework version: 9.26.1
Aimeos Laravel version: * 2022.07.2
PHP Version: 8.1.9
Environment: Linux

My category links are like this in the main menu:
/category~{id}

How can I make them only:
/category

User avatar
aimeos
Administrator
Posts: 7866
Joined: 01 Jan 1970, 00:00

Re: How to remove the category id from the routes and keep only the category url segment?

Post by aimeos » 07 Sep 2022, 16:03

That's tricky because the Aimeos code expects the category ID at several places and also in the Laravel routes. You would have to change the routing in aimeos-laravel, the code for resolving the path in the catalog frontend controller and removing the category ID in the templates. Furthermore, you have to make sure the all category paths are unique and keep care about site and locale handling too.
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

akropivko
Posts: 36
Joined: 20 Jan 2021, 12:49

Re: How to remove the category id from the routes and keep only the category url segment?

Post by akropivko » 05 Sep 2023, 21:07

That's tricky because...
I just checked several Laravel websites from Aimeos Showcases (https://aimeos.org/showcases). I found no showcase with the character '~' in the category URL. Also, I'm 99% sure my client will ask me to remove it too. So... probably it would be a very good idea to simplify the process of removing this character, perhaps through configuration.
Okay, if not removing it entirely, at least changing "~" to something like "/"? Just to avoid alarming the SEO experts.

User avatar
aimeos
Administrator
Posts: 7866
Joined: 01 Jan 1970, 00:00

Re: How to remove the category id from the routes and keep only the category url segment?

Post by aimeos » 06 Sep 2023, 09:25

Using "/" as separator would conflict with the catalog home and/or catalog detail route:
https://github.com/aimeos/aimeos-larave ... #L259-L262

Then, you will have to use a prefix like "c/" for the aimeos_shop_tree route. The current routing is optimized for short top level URL because "~" as separator is nothing that affects SEO. Nevertheless, you can adapt it to whatever you prefer. Only "/category_name" will not work at all because that routes are reserved for the product detail pages (for SEO reasons).
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

Post Reply