In Magento EE 1.12.0.2 (CE 1.7.0.2 comparable) we had custom URL rewrites for a cusom module. They look like this:
+-------+--------------+------------------+----------------------------------+--------+------+--------+---------+
| store | id_path | request_path | target_path | system | opts | cat_id | prod_id |
+-------+--------------+------------------+----------------------------------+--------+------+--------+---------+
| 1 | insurance/10 | carinsurance/ | insurance/form/index/sku/car/ | 0 | NULL | NULL | 10 |
| 1 | insurance/13 | travelinsurance/ | insurance/form/index/sku/travel/ | 0 | NULL | NULL | 13 |
| 1 | insurance/8 | houseinsurance/ | insurance/form/index/sku/house/ | 0 | NULL | NULL | 8 |
+-------+--------------+------------------+----------------------------------+--------+------+--------+---------+
Now after an upgrade to EE 1.14.2.4 (CE 1.9.2.4 comparable) the custom URL rewrites no longer work and we are getting a Magento 404 page.
During the upgrade we've followed all the necessary steps regarding URL rewrites (running the shell scripts, re-indexing, etc...)
How can I fix this and get the custom rewrites to work again?
1 Answer 1
Apparently something has changed in finding rewrites by the current request path. Before the trailing / did work and now it is searching for a rewrite which has a request_path that matches the current request's path without the slash.
Also, in Magento EE the Enterprise_UrlRewrite module and its rewrites are responsible for that.
I solved this by removing the trailing slashes from all my custom rewrites using an upgrade script. Here's a fragment of the code that does the magic:
/** @var $faultyRewrites Enterprise_UrlRewrite_Model_Resource_Url_Rewrite_Collection */
$faultyRewrites = Mage::getResourceModel('enterprise_urlrewrite/url_rewrite_collection')
->addFieldToFilter('request_path', array('like' => '%/'))
->addFieldToFilter('store_id', array('in' => $stores))
->addFieldToFilter('is_system', 0);
foreach ($faultyRewrites as $faultyRewrite) {
/** @var $faultyRewrite Enterprise_UrlRewrite_Model_Url_Rewrite */
$faultyRewrite->setRequestPath(preg_replace("!/$!", "", $faultyRewrite->getRequestPath()));
$faultyRewrite->setIdentifier(preg_replace("!/$!", "", $faultyRewrite->getIdentifier()));
}
try {
$faultyRewrites->save();
} catch (Exception $e) {
Mage::logException($e);
}
For CE you could also run this using the Core URL rewrite collection: Mage::getResourceModel('core/url_rewrite_collection'). Also you can skip the line that strips off the trailing / of the identifier:
// Remove this line from the script above for CE
$faultyRewrite->setIdentifier(preg_replace("!/$!", "", $faultyRewrite->getIdentifier()));
-
1where you have added this changes? can you please provide me path? we have same issue.Jalpesh Patel– Jalpesh Patel2016年06月27日 11:51:21 +00:00Commented Jun 27, 2016 at 11:51
-
I have added this in an upgrade script. You need to have a custom module to add the script. Read more about this here: inchoo.net/magento/…7ochem– 7ochem2016年06月27日 11:54:46 +00:00Commented Jun 27, 2016 at 11:54
-
Nice solution. My category url issue was fix but still we have product detail page url issue.Our product detail page not work with id or url key. It was work before product id. Like www.example.com/catalog/product/view/id/1863/ You have any idea on that?Jalpesh Patel– Jalpesh Patel2016年06月28日 07:11:48 +00:00Commented Jun 28, 2016 at 7:11
-
Explore related questions
See similar questions with these tags.