Clean URLs in PrestaShop 9
SEO optimization is essential for any successful online store. One key aspect is offering friendly, clean URLs without numeric IDs that add no value to rankings or user experience.
By default, PrestaShop 9.x manages URLs with IDs, which is far from ideal for SEO. This post presents a free PrestaShop module based on an advanced override of the Dispatcher.php class that removes those IDs from product, category, CMS, manufacturer and supplier URLs, generating clean, clear and fully functional links tailored to PrestaShop's multistore and multi-language ecosystem.
Complete tutorial: Step-by-step module installation
What is this free PrestaShop module and why should you use it?
PrestaShop's engine uses URLs that include internal IDs by default, for example:
yoursite.com/products/15-red-t-shirt.html
These IDs do nothing for SEO and compromise clarity for users and search engines. This free PrestaShop module replaces the URL generation and resolution logic so that it uses only the product slug and its category, achieving clean URLs like:
yoursite.com/t-shirts/red-t-shirt.html
By doing so, you improve user experience, trust and SEO rankings.
Features of the free PrestaShop module
/override/classes/Dispatcher.phpTechnical aspects of the Dispatcher.php override
This free PrestaShop module overrides the following key Dispatcher functions:
loadRoutes
Redefines rules so that product URLs contain {category}/{rewrite}.html and category URLs are just {rewrite}, among others.
getController
- Intercepts the requested URL and cleans the relevant part by removing the
.htmlextension - Retrieves
id_productfrom the database by the product slug (last part of the path) - Gets the ID and slug of the default category for the URL
- Sets the correct controller to load the page
- Uses the parent controller for URLs that are neither products nor categories
Essential snippet to add the category to the product URL:
// In getController, resolution with category for product
$id_product = $db->getValue('SELECT id_product FROM ' . _DB_PREFIX_ . 'product_lang WHERE link_rewrite = ...');
if ($id_product) {
// Get product default category
$id_category = $db->getValue('SELECT id_category_default FROM ' . _DB_PREFIX_ . 'product WHERE id_product = ' . (int)$id_product);
$category_rewrite = $db->getValue('SELECT link_rewrite FROM ' . _DB_PREFIX_ . 'category_lang WHERE id_category = ' . (int)$id_category . ' AND id_lang = ' . $id_lang);
$_GET['id_product'] = $id_product;
$_GET['id_category'] = $id_category;
$this->controller = 'product';
return $this->controller;
}
Benefits for your store
SEO Optimized
Clean URLs, better for search engines
Better UX
Clear and professional user experience
Multi?language
Multi?language and multi?store support without conflicts
Compatible
Works with the back office and internal links
Error?free
Avoids conflicts with mixed IDs
Maintainable
Clean code, easy to extend
How to integrate this free PrestaShop module
Download and place the file
Place the Dispatcher.php file in the /override/classes/ path of your PrestaShop 9.x store.
Clear the cache
Remove the var/cache/prod or var/cache/dev folder so that the system regenerates the routes and applies the changes.
Check the slugs
Make sure that slugs and categories are correctly defined in the back office to avoid errors with clean URLs.
Test your store
Visit your store to visually check that URLs appear without IDs and that the category is included in the product URL.
Important Warning
Before using this free PrestaShop module, make sure to check that there are no duplicate slugs in your store for:
- Products
- Categories
- CMS pages
- Manufacturers
- Suppliers
Duplicate slugs will cause conflicts in the generation and resolution of friendly URLs, affecting SEO and user experience. Please fix any duplicate slug before uploading the Dispatcher file to avoid problems.