Magento-删除多个产品URL重写
在my CE-1.9.0 store中,我的产品当前创建以下url重写:Magento-删除多个产品URL重写,magento,url,url-rewriting,Magento,Url,Url Rewriting,在my CE-1.9.0 store中,我的产品当前创建以下url重写: http://example.com/product-name http://example.com/category/product-name http://example.com/another-category/subcategory/product-name 然而,在我的商店里,我希望能够停止为类别版本创建重写。我将System>Configuration>Catalog>Catalog>Use Categori
http://example.com/product-name
http://example.com/category/product-name
http://example.com/another-category/subcategory/product-name
然而,在我的商店里,我希望能够停止为类别版本创建重写。我将System>Configuration>Catalog>Catalog>Use Categories Path for Product url
设置为No
,因此这些额外的重写是不必要的。再加上我的商店有大约500000种产品,所以这些额外的url在core_url_rewrite`表中占据了大量空间
因此,我的目标是只留下这些版本:
http://example.com/product-name
如果我截断core_url_rewrite表并重新编制索引,那么只会创建这些版本,因此只有在创建新产品时才会创建这些版本。我的目录太大了,所以我无法继续截断并从头开始重建表,因为重建需要几个小时
在我的帮助下,我找到了在创建产品时负责创建重写的文件。它是:
app/code/core/Mage/Catalog/Model/Resource/Product/Collection.php
但是,答案不再有效,因为核心文件中的代码已更改
在第538行的这个文件中有\u afterLoad
函数,它是
$this->_addUrlRewrite($this->_urlRewriteCategory);
这个函数\u addUrlRewrite
但是我在这个函数中做了很多修改,但是没有成功。全部功能是:
protected function _addUrlRewrite()
{
$urlRewrites = null;
if ($this->_cacheConf) {
if (!($urlRewrites = Mage::app()->loadCache($this->_cacheConf['prefix'] . 'urlrewrite'))) {
$urlRewrites = null;
} else {
$urlRewrites = unserialize($urlRewrites);
}
}
if (!$urlRewrites) {
$productIds = array();
foreach($this->getItems() as $item) {
$productIds[] = $item->getEntityId();
}
if (!count($productIds)) {
return;
}
$select = $this->_factory->getProductUrlRewriteHelper()
->getTableSelect($productIds, $this->_urlRewriteCategory, Mage::app()->getStore()->getId());
$urlRewrites = array();
foreach ($this->getConnection()->fetchAll($select) as $row) {
if (!isset($urlRewrites[$row['product_id']])) {
$urlRewrites[$row['product_id']] = $row['request_path'];
}
}
if ($this->_cacheConf) {
Mage::app()->saveCache(
serialize($urlRewrites),
$this->_cacheConf['prefix'] . 'urlrewrite',
array_merge($this->_cacheConf['tags'], array(Mage_Catalog_Model_Product_Url::CACHE_TAG)),
$this->_cacheLifetime
);
}
}
foreach($this->getItems() as $item) {
if (empty($this->_urlRewriteCategory)) {
$item->setDoNotUseCategoryId(true);
}
if (isset($urlRewrites[$item->getEntityId()])) {
$item->setData('request_path', $urlRewrites[$item->getEntityId()]);
} else {
$item->setData('request_path', false);
}
}
}
也许有一种方法:
System>Configuration>Catalog>Search Engine Optimizations>Use categories path for product url
&System>Configuration>Catalog>Search Engine Optimizations>Use Canonical Link Meta Tag for categories
这似乎没有任何效果。您在重新索引之前刷新了缓存启动?是的,要确认何时截断并重新编制索引,仅为http://example.com/product-name
版本。但是新产品仍然会创建3个版本。如果这是Magento的一种自然行为,您可以通过一个模块来覆盖它,或者您可以在重新索引后使用SQL脚本来减少核心url重写表大小<代码>(1)显然更好!///检查并找到一种方法之前,可能有一种方法:System>Configuration>Catalog>Search Engine Optimizations>Use categories path for product url
&System>Configuration>Catalog>Search Engine Optimizations>Use Canonical Link Meta Tag for categories
这似乎没有任何效果您刷新了在重新索引之前启动缓存?是的,为了确认何时截断和重新索引,仅为http://example.com/product-name
版本。但是新产品仍然会创建3个版本。如果这是Magento的一种自然行为,您可以通过一个模块来覆盖它,或者您可以在重新索引后使用SQL脚本来减少核心url重写表大小<代码>(1)显然更好!///在你找到方法之前,先检查一下