Extending Link Rewrite Length in PrestaShop 9.x: A Developer's Quick Fix
Extending Link Rewrite Length in PrestaShop 9.x
A PrestaShop forum thread highlights a common issue faced by merchants dealing with products or categories that have names exceeding the default 128-character limit for the link_rewrite field. The original poster, 'chief', encountered this limitation while migrating to PrestaShop 9.0.2 and sought a solution to increase the link_rewrite length to 255 characters.
The user had previously implemented changes in older PrestaShop versions (1.7.x) by modifying the database, a PHP form file, and the Product.php class. However, these modifications were no longer effective in PrestaShop 9.x.
The Solution:
ComGrafPL provided the key to resolving this issue by pinpointing the relevant files where the MAX_LINK_REWRITE_LENGTH constant is defined. The solution involves modifying two files:
/src/Core/Domain/Category/SeoSettings.php/src/Core/Domain/Product/ProductSettings.php
Within these files, locate the following line:
public const MAX_LINK_REWRITE_LENGTH = 128;
Change the value from 128 to 255 (or your desired maximum length) in both files. For example:
public const MAX_LINK_REWRITE_LENGTH = 255;
Important Considerations:
- Database Modification: While the thread doesn't explicitly mention it, ensure that the corresponding database column (
link_rewritein theps_product_langandps_category_langtables) is also adjusted to accommodate the increased length (e.g.,VARCHAR(255)). - URL Length Limits: Be mindful of practical URL length limits imposed by browsers and search engines. While technically you can increase the
link_rewritelength, excessively long URLs can negatively impact SEO and user experience. - Testing: After making these changes, thoroughly test the functionality by creating or updating products and categories with longer names to ensure that the
link_rewritefield is correctly populated and that URLs are generated as expected.
This quick fix allows PrestaShop 9.x users to overcome the default link_rewrite length limitation, enabling them to create more descriptive and SEO-friendly URLs for their products and categories.