After several messed up imports, I've been left with a load of URL rewrites that I need to remove.
I'm running Enterprise 1.13
When I've had this problem in community, I've simply truncated core_url_rewrite
, and the reindexed.
However, in Enterprise, I notice that there a number of different tables that control rewrites.
enterprise_url_rewrite
enterprise_url_rewrite_category_cl
enterprise_url_rewrite_product_cl
enterprise_url_rewrite_redirect
enterprise_url_rewrite_redirect_cl
enterprise_url_rewrite_redirect_rewrite
Am I safe to truncate all of them?
I fully anticipate for someone to tell me that I should never truncate these tables, so apologies for the naivety in advance.
Best Answer
We we're in the similar situation as you James. After a lot of digging this is what I came up with:
The
core_url_rewrite
table is now deprecated, instead Magento EE 1.13 now stores the rewrites inenterprise_url_rewrite
.Tables:
enterprise_*_category_rewrite
usecatalog_*_entity_url_key
tables to rebuild the two rewrite tables when you runphp indexer.php --reindex catalog_url_*
When you add a 'URL Redirect' in admin Catalog->URL Redirects for a custom URL it gets added to the
enterprise_url_rewrite_redirect
table and the flag for Magento that the index is now outdated is entered intoenterprise_url_rewrite_redirect_cl
table which when runningphp indexer.php --reindex url_redirect
rebuilds theenterprise_url_rewrite_redirect_rewrite
table.Quick note, any table ending in _cl is safe to truncate, the 'CL' stands for Change Log and is used by Magento to check if re-indexing is required.
As far as the URL Key tables go, I'm still a bit clueless as to why there two URL Key entries one in
catalog_*_entity_url_key
and one incatalog_*_entity_varchar
(attribute id 90), but I assume this is what happens:When you create a new product/category Magento uses the name to generate a url_key which is placed in
catalog_*_entity_url_key
AND in thecatalog_*_entity_varchar
, but the primary table used by Magento is thecatalog_*_entity_url_key
because if you truncate it and runphp indexer.php --reindex catalog_url_*
yourenterprise_*_category_rewrite
tables will be empty and products/categories in the frontend will display ugly urls i.e.http://example.com/catalog/product/view/id/123/etc/etc
(not SOE friendly) I believe the two tables are related and are used to build theenterprise_url_rewrite
table because this table stores a 'request_path' most likely the url_key inside thecatalog_*_entity_varchar
table and an 'identifier' which is the primary URL Key from thecatalog_*_entity_url_key
table. I could be completely wrong about url_key and varchar tables, so I'm just thinking out loud.Anyway to successfully truncate and rebuilt all rewrite tables you can execute:
and then run:
If you also truncate
enterprise_url_rewrite_redirect
then you will loose all of your custom redirects that you see in your admin panel, perhaps this is your goal since you were left with a ton of useless URLs. As long as you DO NOT truncate the '*_entity_url_key' tables you'll be fine.Our story was a little different, because we had duplicate URL Keys and major problems with product names from excel imports after upgrading to 1.13 from 1.11 so I wrote this quick script to reset the
catalog_product_entity_url_key
table and the URL keys and URL paths in thecatalog_product_entity_varchar
table using product names. I attached the code below, but if you use it, use it at your own risk.The code can be tweaked to use Magentos formatKey method here: http://www.magentocommerce.com/wiki/3_-_store_setup_and_management/seo/url_key_characters_conversion unfortunately I came across the wiki after I updated all the keys so I didn't bother reupdating everything again.
Hope that helps :)!