我使用magento 1.4.1.1,在后端配置中,有一个选项:删除产品的类别url,以及产品网址为http://www.yourdomain.com/products.html,这是完美的功能。但类别的网址仍然有层,我如何删除类别url的父网址?所以当我尝试更改分类图层时,没关系。如何将magento类别的网址更改为short url(对Google友好)?
感谢提前,对不起我的英文不好。
我使用magento 1.4.1.1,在后端配置中,有一个选项:删除产品的类别url,以及产品网址为http://www.yourdomain.com/products.html,这是完美的功能。但类别的网址仍然有层,我如何删除类别url的父网址?所以当我尝试更改分类图层时,没关系。如何将magento类别的网址更改为short url(对Google友好)?
感谢提前,对不起我的英文不好。
编辑文件/app/code/core/Mage/Catalog/Model/Url.php以评论这些行(见下文)对于1.4应该是第673至679行,如果不是搜索文件中的代码。 然后刷新网址在管理改写 - >系统 - >索引管理
//if (null === $parentPath) {
//$parentPath = $this->getResource()->getCategoryParentPath($category);
//}
//elseif ($parentPath == '/') {
$parentPath = '';
//}
太棒了!只是想发表评论,并说这个修补程序也适用于Magento 1.7 :) – Sean 2012-12-07 13:24:36
不要更改核心代码。重写模型并在本地代码池中进行更改。 – Nick 2013-03-07 10:16:24
@尼克这不能说经常。 – demonkoryu 2013-06-21 10:22:52
我查了一下,但没有发现任何有用的,所以我最终这个解决方案
1日我创建了一个观察者运行类别保存后, 应用程序/代码/本地/命名空间/模块的/ etc/config.xml中
<events>
<catalog_category_save_commit_after>
<observers>
<namespace_module_Model_observer>
<type>singleton</type>
<class>namespace_module/observer</class>
<method>setUrlRedirect</method>
</namespace_module_Model_observer>
</observers>
</catalog_category_save_commit_after>
</events>
然后在我的观察我添加自定义URL重写,使我们的类别URL直销TLY访问(example.com/deeply-layered-catogry.html)
public function setUrlRedirect($observer) {
$e = $observer->getEvent();
$c = $e->getCategory();
// getting updated data,
$data = $observer->getDataObject()->getData();
$c = Mage::getModel("catalog/category")->load($c->getId());
$url = $c->getUrl();
$handle = $data['url_key'];
$p = 'catalog/category/view/id/' . $c->getId(); /*$handle . ".html";*/
$id = 'seo-frindly/cat-' . $c->getId() .'.html';
$urlMdoule = Mage::getModel('core/url_rewrite');
$storeId = Mage::app()->getStore()->getStoreId();
if ( $urlMdoule->loadByIdPath($id)->getId()) {
// update
$o = $urlMdoule->loadByIdPath($id);
$o->setIsSystem(0)
->setStoreId($storeId)
->setOptions('no')
->setTargetPath($p)// Put the actual path
->setRequestPath($handle .'.html')
->setRedirect(false)
->save();
} else {
// new
$urlMdoule->setIsSystem(0)
->setStoreId($storeId)
->setOptions('no')
->setIdPath($id)
->setTargetPath($p)// Put the actual path
->setRequestPath($handle .'.html')
->setRedirect(false)
->save();
}
return;
}
现在当你永远保存的类别,这将是从短URL访问,
只需添加的rel =“规范“属性在头,所以谷歌将索引较短的seo firendly链接
请确保重建目录缓存。 – mivec 2011-03-11 12:41:11