Issue
- We have several Web Content articles where the friendly URL contains some dots and we would like to have hyphens instead.
- Changing them manually is not only hard but we would also like to implement a workflow to make sure that they are replaced with hyphens in the future.
Environment
- DXP 7.4
Resolution
- Use the attached script to replace all the characters.
- The script will replace any dots with hyphens that are found in the friendly URLs, in all the sites.
NOTE: Be sure to take a backup of your database prior to making any changes. Always test the changes in a lower environment before making changes in production.
Making manual changes to the database is not recommended, and should be carefully assessed based on your own business needs and risk factors. Any such operation is performed at the sole discretion of your own team.
Notes
- Unfortunately, the dryRun mode cannot fully be trusted, due to how friendly URLs work at the moment.
If you add a friendly URL that may be a duplicate, Liferay will add a number to it, e.g. -1.
Example:- article 1 friendly URL: test-test
- article 2 friendly URL: test.test
↳ this should be changed to test-test but then it will be the same as an existing friendly URL. Because of that, it will be changed to test-test-1, and if that already exist, then it will be changed to test-test-2 and so on.
- The script should handle that, so the friendly URL that you see during an actual execution will show you the correct value. But since the dryRun does not know if the new friendly URLs (the ones with the hyphens) interfere with any of the existing friendly URLs in the database, that’s why it may not be 100% correct.
- This can be solved by some extensive testing and manually fixing the couple of records.
Additional Information