Make sure the URL you’re trying to achieve is in fact unique.
There is a reason Magento appends these numbers to the end of your URLs, because it actually already exists. It’s like creating two categories with the same name in WordPress, the second category will have the URL “/category-2/”.
Step 2 Do a database backup
Open up PHPMyAdmin or something similar.
Find the Core_url_rewrite table.
Search for your url in the request path. In my example I typed: ‘hats%’ this will find anything beginning with hats in the url.
Just remember if you hard linked this page it will now 404. So if there is a risk of this, make sure you create a new redirect after this for that page.
Delete all rows from the search results.
Reindex your Catalog URL rewrites.
Go back to the category or product and click save.
Your urls should now be as desired!
The upgrade will help with the underlying cause of this, but will not correct it. You will still need to run through this process regardless.