我们和您詹姆斯的处境相似。经过大量的挖掘,这是我想到的:
core_url_rewrite
现在不推荐使用该表,而现在Magento EE 1.13将重写存储在中enterprise_url_rewrite
。
表:运行时
enterprise_*_category_rewrite
使用catalog_*_entity_url_key
表重建两个重写表php indexer.php --reindex catalog_url_*
当您在admin Catalog-> URL重定向中为自定义URL添加“ URL重定向”时,它将被添加到enterprise_url_rewrite_redirect
表中,并且Magento标记现在已过时的标志被输入到enterprise_url_rewrite_redirect_cl
表中,运行时php indexer.php --reindex url_redirect
该enterprise_url_rewrite_redirect_rewrite
表将重建表。
快速说明,任何以_cl结尾的表都可以安全地截断,“ CL”代表更改日志,Magento使用它来检查是否需要重新索引。
至于URL Key表,我仍然不清楚为什么有两个URL Key项一进catalog_*_entity_url_key
一出catalog_*_entity_varchar
(属性ID 90),但是我认为这是会发生的:
当你创建一个新的产品/类别的Magento使用该名称生成被放置在一个url_key catalog_*_entity_url_key
并在catalog_*_entity_varchar
,但Magento的使用的主要表是catalog_*_entity_url_key
因为如果你截断并运行php indexer.php --reindex catalog_url_*
你的enterprise_*_category_rewrite
表将是空的,产品/类别前端将显示丑陋的url,即http://example.com/catalog/product/view/id/123/etc/etc
(不支持SOE)我相信这两个表是相关的,并且用于构建enterprise_url_rewrite
表,因为该表最有可能在表内部存储“ request_path” catalog_*_entity_varchar
和“ identifier”,而“ identifier”是主要表catalog_*_entity_url_key
表中的URL密钥。我可能对url_key和varchar表完全错了,所以我只是大声考虑。
无论如何成功截断并重建所有重写表,您都可以执行:
SET FOREIGN_KEY_CHECKS = 0;
TRUNCATE TABLE `core_url_rewrite`;
TRUNCATE TABLE `enterprise_catalog_category_rewrite`;
TRUNCATE TABLE `enterprise_catalog_product_rewrite`;
TRUNCATE TABLE `enterprise_url_rewrite`;
TRUNCATE TABLE `enterprise_url_rewrite_category_cl`;
TRUNCATE TABLE `enterprise_url_rewrite_product_cl`;
TRUNCATE TABLE `enterprise_url_rewrite_redirect_cl`;
TRUNCATE TABLE `enterprise_url_rewrite_redirect_rewrite`;
SET FOREIGN_KEY_CHECKS = 1;
然后运行:
sudo php indexer.php --reindex catalog_url_product
sudo php indexer.php --reindex catalog_url_category
sudo php indexer.php --reindex url_redirect
如果您也进行截断,enterprise_url_rewrite_redirect
那么您将失去在管理面板中看到的所有自定义重定向,这也许是您的目标,因为您留下了大量的无用URL。只要您不截断“ * _entity_url_key”表,就可以了。
我们的故事有所不同,因为从1.11升级到1.13后,我们遇到了重复的URL键和excel导入产品名称的主要问题,所以我写了这个快速脚本来使用产品重置catalog_product_entity_url_key
表以及表中的URL键和URL路径catalog_product_entity_varchar
名称。我在下面附上了代码,但是如果您使用它,请自行承担风险。
<?php
include_once('app/Mage.php');
Mage::app();
$dbHandle = Mage::getSingleton('core/resource')->getConnection('core_write');
$productCounter = 0;
$nameFixCounter = 0;
$vUrlKeyFixCounter = 0;
$urlPathCounter = 0;
$urlKeyCounter = 0;
$productCollection = $dbHandle->query("SELECT entity_id, sku FROM catalog_product_entity");
while($product = $productCollection->fetch()) {
$dataString = null;
$oldProductName = $dbHandle->query("SELECT value FROM catalog_product_entity_varchar WHERE entity_id = '".$product['entity_id']."' AND attribute_id = 65")->fetch();
$oldVarcharUrlKey = $dbHandle->query("SELECT value FROM catalog_product_entity_varchar WHERE entity_id = '".$product['entity_id']."' AND attribute_id = 90")->fetch();
$oldUrlPath = $dbHandle->query("SELECT value FROM catalog_product_entity_varchar WHERE entity_id = '".$product['entity_id']."' AND store_id = 0 AND attribute_id = 91")->fetch();
$oldUrlKey = $dbHandle->query("SELECT value FROM catalog_product_entity_url_key WHERE entity_id = '".$product['entity_id']."'")->fetch();
$newProductName = preg_replace('/\s+/', ' ', trim(preg_replace('/[^\x20-\x21\x23-\x2B\x2D-\xE7]/', ' ', $oldProductName['value'])));
$newUrlKey = preg_replace('/\s+/', '-', trim(preg_replace('/[^\x30-\x39\x61-\x7A]/', ' ', strtolower($newProductName))));
if (strcmp($oldProductName['value'], $newProductName)) {
echo "-[".$oldProductName['value']."]\n";
echo "+[".$newProductName."]\n";
$dbHandle->query('UPDATE catalog_product_entity_varchar SET value = "'.$newProductName.'" WHERE entity_id = "'.$product['entity_id'].'" AND attribute_id = 65');
++$nameFixCounter;
}
if (strcmp($oldVarcharUrlKey['value'], $newUrlKey)) {
echo "-[".$oldVarcharUrlKey['value']."]\n";
echo "+[".$newUrlKey."]\n";
if ($oldVarcharUrlKey['value'] === null) {
$dbHandle->query("INSERT INTO catalog_product_entity_varchar (entity_type_id, attribute_id, store_id, entity_id, value) VALUES ('4', '90', '0', '".$product['entity_id']."', '".$newUrlKey."')");
} else {
$dbHandle->query("UPDATE catalog_product_entity_varchar SET value = '".$newUrlKey."' WHERE entity_id = '".$product['entity_id']."' AND attribute_id = 90");
}
++$vUrlKeyFixCounter;
}
if (strcmp($oldUrlPath['value'], $newUrlKey.'.html')) {
echo "-[".$oldUrlPath['value']."]\n";
echo "+[".$newUrlKey.".html]\n";
if ($oldUrlPath['value'] === null) {
$dbHandle->query("INSERT INTO catalog_product_entity_varchar (entity_type_id, attribute_id, store_id, entity_id, value) VALUES ('4', '91', '0', '".$product['entity_id']."', '".$newUrlKey.".html')");
} else {
$dbHandle->query("UPDATE catalog_product_entity_varchar SET value = '".$newUrlKey.".html' WHERE entity_id = '".$product['entity_id']."' AND store_id = 0 AND attribute_id = 91");
}
++$urlPathCounter;
}
if (strcmp($oldUrlKey['value'], $newUrlKey)) {
echo "-[".$oldUrlKey['value']."]\n";
echo "+[".$newUrlKey."]\n";
if ($oldUrlKey['value'] === null) {
$dbHandle->query("INSERT INTO catalog_product_entity_url_key (entity_type_id, attribute_id, store_id, entity_id, value) VALUES ('4', '90', '0', '".$product['entity_id']."', '".$newUrlKey."')");
} else {
$dbHandle->query("UPDATE catalog_product_entity_url_key SET value = '".$newUrlKey."' WHERE entity_id = '".$product['entity_id']."'");
}
++$urlKeyCounter;
}
$report = "[".++$productCounter."] ";
$report .= "NAME: [".(strcmp($oldProductName['value'], $newProductName)?'!=':'==')."] ";
$report .= "V_KEY: [".(strcmp($oldVarcharUrlKey['value'], $newUrlKey)?'!=':'==')."] ";
$report .= "PATH: [".(strcmp($oldUrlPath['value'], $newUrlKey.'.html')?'!=':'==')."] ";
$report .= "KEY: [".(strcmp($oldUrlKey['value'], $newUrlKey)?'!=':'==')."]\n";
echo $report;
}
echo 'Total Products: ['.$productCounter.'] Names: ['.$nameFixCounter.'] V_Keys: ['.$vUrlKeyFixCounter.'] Paths: ['.$urlPathCounter.'] Keys: ['.$urlKeyCounter.']';
可以对代码进行调整,以在此处使用Magentos formatKey方法:http : //www.magentocommerce.com/wiki/3_-_store_setup_and_management/seo/url_key_characters_conversion不幸的是,在更新所有密钥之后,我遇到了Wiki,因此不必费心更新一切再次。
希望有帮助:)!
core_url_rewrite
并奏效。