I've truncated the core_url_rewrite
table with about 5000000 records. After that I run the Catalog URL Rewrite Indexer which created 1782612 records. Then I run it again and the table had 2251930 records. So, every time I run the indexer, I get more records in the table. Does anyone know why?
Thanks
-
See comments: magento.stackexchange.com/questions/5655/…– mageUzCommented Apr 11, 2014 at 6:54
-
Closing as duplicate; please update your question if that seems inappropriate.– benmarksCommented Apr 26, 2014 at 15:26
2 Answers
I also asked a similar question a while back:
Magento core_url_rewrite table excessively large
I've managed to stabalize the issue as follows:
Step 1: Rewrite the Catalog URL model (Using your own module: How To)
Note: If you overwrite the core file without using a rewrite this will render your instance of Magento incapable of future upgrades.
As per Jahnni's solution on the MagentoCommerce boards, app/code/core/Mage/Catalog/Model/Url.php
around line 807
From:
if ($product->getUrlKey() == '' && !empty($requestPath)
&& strpos($existingRequestPath, $requestPath) === 0
)
To:
if (!empty($requestPath)
&& strpos($existingRequestPath, $requestPath) === 0
)
Step 2: Truncate
Truncate the core_url_rewrite
table
Step 3: Reindex & Flush Caches
Initiate the re-indexing process on Core URL Rewrites. Thereafter, you'll want to flush the Magento cache & storage cache.
System
→ Cache Management
→ Flush Magento Cache
System
→ Cache Management
→ Flush Cache Storage
Voila, you're all set. You'll notice if you re-run the indexer, the table should stay constant in size (unless you've added more products inbetween or if you have duplicate category names).
-
2A word of warning: if you
truncate core_url_rewrite
you are deleting all of your custom rewrites as well as the system ones - these won't be regenerated by the subsequent reindex and will be lost permanently! Commented Jul 17, 2015 at 16:08 -
True. instead delete the entitytype="product" (for products alone) Commented Jun 16, 2019 at 9:40
I guess there are several reasons why this may happen. One of the more obvious is when you have several products with the same URL key.
Given you have two products both named "Test" with both products having the same URL key "test". Magento will create two URL rewrites: one for test.html and one for test-2.html. If you re-run the Rewrite Indexing process, Magento will start creating a further redirect for the test-2.html URL and so on. As you can guess that's not a wanted behaviour but it happens pretty often, especially with stores having configurable products with many simple products sharing the same name (e.g. clothes with different sizes and colors).
To dive deeper into this problem and find the cause for your growing URL rewrite table we would need more detail, I'm afraid.