Redirects in Magento have me utterly confused. Enterprise 1.13 has not helped the situation. My problem is this, I want to add a product link widget to the home page but newer products do not show up. I've traced the problem back to Mage_Catalog_Block_Widget_Link::getHref()
:
$urlRewriteResource = Mage::getResourceSingleton('core/url_rewrite');
$href = $urlRewriteResource->getRequestPathByIdPath($this->getData('id_path'), $store);
Now, the Mage_Core_Model_Url_Rewrite
model uses the table core_url_rewrite
. And my new products do not exist in that table! Weird, because they are Enabled, visible in Catalog, they have a url_key and I can navigate to the product page just fine. So they must exist in one of the other Enterprise tables. Which one?
core_url_rewrite -> Url Rewrites
enterprise_catalog_category_rewrite -> Relation between rewrites and categories
enterprise_catalog_product_rewrite -> Relation between rewrites and products
enterprise_url_rewrite -> URL Rewrite
enterprise_url_rewrite_redirect -> Permanent redirect
enterprise_url_rewrite_redirect_rewrite -> Relation between rewrites and redirects
Yep, it exists in the enterprise_url_rewrite
table …
+----------------+-----------------------+--------------------------------+-----------+------+-----------------------+-----+----------+----------+-------------+
| url_rewrite_id | request_path | target_path | is_system | guid | identifier | inc | value_id | store_id | entity_type |
+----------------+-----------------------+--------------------------------+-----------+------+-----------------------+-----+----------+----------+-------------+
| 31282261 | product-1-working | catalog/product/view/id/256037 | 1 | xyz | product-1-working | 1 | 9236282 | 0 | 3 |
| 31294573 | product-2-not-working | catalog/product/view/id/268697 | 1 | xyz | product-2-not-working | 1 | 9610723 | 0 | 3 |
+----------------+-----------------------+--------------------------------+-----------+------+-----------------------+-----+----------+----------+-------------+
2 rows in set (0.00 sec)
but not in the core_url_rewrite
table …
+----------------+----------+-------------+------------+----------------+-----------------------+--------------------------------+-----------+---------+-------------+
| url_rewrite_id | store_id | category_id | product_id | id_path | request_path | target_path | is_system | options | description |
+----------------+----------+-------------+------------+----------------+-----------------------+--------------------------------+-----------+---------+-------------+
| 3512685 | 1 | NULL | 256037 | product/256037 | product-1-working.htm | catalog/product/view/id/256037 | 1 | NULL | NULL |
+----------------+----------+-------------+------------+----------------+-----------------------+--------------------------------+-----------+---------+-------------+
1 row in set (0.34 sec)
Next I tried reindexing the url indexes (and if someone could explain the difference between these I'd appreciate it)
$ php shell/indexer.php --reindex catalog_url_product,url_redirect
Product URL Rewrites index was rebuilt successfully
URL Redirects index was rebuilt successfully
Nope, still nothing. What do I have to do to get products in the core_url_rewrite
table, other than by creating them manually myself?
Best Answer
In Magento Enterprise the is a new module for storing url rewrite
Enterprise_UrlRewrite
. This module contains new tables for storing the rewrites, some layout files for the admin section, a new admin html controller and a new url matcher to name but a few items.To understand when the enterprise system uses the new tables for saving rewrites we can first look into the controller
Enterprise_UrlRewrite_Adminhtml_UrlrewriteController
, here we find the function_getRedirect
which is used to to load the current redirect being worked on and returns a model of typeEnterprise_UrlRewrite_Model_Redirect
.If we then look into the config.xml for
Enterprise_UrlRewrite
you can see that it has it's own table information stored so that when the model is being used it does not use the standard community tables.The structure of these new tables, is in my opinion vast improvement of the community editions single table, as the category and product information is moved into separate tables and also the redirect information is also separated.