如何将magento类别网址更改为短网址(对谷歌友好)?

发布于 2024-10-21 02:49:13 字数 250 浏览 3 评论 0原文

我使用magento 1.4.1.1,在后端配置中,有一个选项:删除产品的类别url,嗯,产品url是 http://www.yourdomain.com/products.html,这是完美的功能。但类别 url 仍然有图层,如何删除类别 url 的父 url?所以当我尝试更改类别层时,就可以了。

预先感谢,抱歉我的英语不好。

I use magento 1.4.1.1, at the backend configuration, there's a option: remove category url for products, well, the product url was http://www.yourdomain.com/products.html, this was perfect feature. but the category url was still has layer, how can I remove the parent url for category url? so when I try to change the categories layer, then it's okay.

Thanks advance, sorry for my poor english.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

仄言 2024-10-28 02:49:13

编辑文件 /app/code/core/Mage/Catalog/Model/Url.php 以注释这些行(见下文)如果不搜索文件中的代码,则应为 1.4 的第 673 至 679 行。
然后在admin中刷新url重写->系统->指数管理

//if (null === $parentPath) {
                   //$parentPath = $this->getResource()->getCategoryParentPath($category);
               //}
               //elseif ($parentPath == '/') {
                   $parentPath = '';
               //}

Edit the file /app/code/core/Mage/Catalog/Model/Url.php as to comment these lines (see below) Should be lines 673 to 679 for 1.4, if not search for the code in the file.
Then refresh url rewrites in admin -> system -> Index management

//if (null === $parentPath) {
                   //$parentPath = $this->getResource()->getCategoryParentPath($category);
               //}
               //elseif ($parentPath == '/') {
                   $parentPath = '';
               //}
╭ゆ眷念 2024-10-28 02:49:13

我搜索了一下,但没有找到任何有用的东西,所以我最终得到了这个解决方案

,首先我创建一个观察者,在保存类别后运行,
app/code/local/namespace/module/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 可以直接访问(example.com/deeply-layered-catogry.xml) 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;

}

现在,当您保存类别时,可以从较短的网址访问它,

只需在 head 中添加 rel="canonical" 属性,这样谷歌就会索引较短的 seo 友好链接

i search a bit but didn't find anything helpful, so i end up with this solution

1st i create a observer the run after the category is saved,
app/code/local/namespace/module/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>

then in my observer i add a custom url rewrite that make our category url directly accessible (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;

}

now when ever you save the category, it will be accessible from the shorter url,

just add the rel="canonical" attribute in head so google will index the shorter seo firendly links

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文