Numbers at the end of a URL Magento 1.9
<p>On our website we used to have loads of links which had 4 digits on the end of them. They looked like this </p>

<pre><code>www.example.com/example-1234.html. 
</code></pre>

<p>The URLs with the numbers had overridden the normal URL which would be like </p>

<pre><code>   www.example.com/example.html.
</code></pre>

<p>We got rid of them by truncating the <code>core_url_rewrite</code> table and this turned the active URL's with numbers at the end of them into 404's. </p>

<p>However, recently I have noticed that these numbers have come back and I'm not really sure why. However, this time they are also effecting category URLs so some of our category URLS look like: </p>

<pre><code>www.example.com/main-category/sub-category-1234/product.html
</code></pre>

<p>I found this article on stackoverflow which was useful:
 <a href="https://stackoverflow.com/questions/13614738/magento-removing-numbers-in-url-key-product-url">Magento - Removing numbers in url key/product url</a> . </p>

<p>However I still don't understand why this is happening. I found that the function <code>getUnusedPath</code> is what is causing these numbers to happen and that it looks like it will only create those numbers at the end of the URL is </p>

<pre><code>if ($rewrite &amp;&amp; $rewrite-&gt;getId()) 
// and $rewrite` is equal to 
$rewrite = $this-&gt;getResource()-&gt;getRewriteByRequestPath($requestPath, $storeId);
</code></pre>

<p>Do you know where I can find out what </p>

<pre><code>getResource()-&gt;getRewriteByRequestPath($requestPath, $storeId);
</code></pre>

<p>does? 
Why are we getting these numbers appearing at the end of the URL? 
Do we have a setting turned on that does this? (the file that does this is located in </p>

<pre><code>app/code/core/Mage/Catalog/Model/Url.php around `line 640` 
</code></pre>

<p>I tried all the different types of saving a product to see if when you save it magento updates the URL but that doesn't work. I then tried to reindex the url rewrites and that didn't do anything either. We have 2 magento websites and on our second magento website this isn't happening and the <code>core_url_rewrite</code> table doesn't have any of the urls with numbers in it. Why is it happening to one of our sites and not the other? How can we stop the URLS from having numbers added on to them and How can we find out why they are being generated?</p>

<p>I have also now found out that this happens every time the url rewrites are reindex as that script is running every time it's reindexed. We index the </p>

<p><code>url_rewrites</code> </p>

<p>every time you save a product. We use unique URLs for all our products but I don't know why it is happening. 
I have also discovered that for the numbers to be added on to the end of the URL it has to fit this regex query </p>

<pre><code>#[0-9a-z/-]+?(-([0-9]+))?('.preg_quote($suffix).')?$#i` 
</code></pre>

<p>(does anyone know what this means? I have tried to look in a REGEX calculator and it doesn't help me make sense of which strings would fit this?</p>