dongzhun1857 2014-01-24 17:37
浏览 70
已采纳

Magento SEO链接

My client knows a little about SEO , but I don't. According to him , our urls are not fine because they are duplicated. Here are the examples of what is happening:   Our website sells cookware, so we have the following categories, for example: Cast iron and grates. The grates category is a subcategory from cast iron.   Knowing that, we have a square grate and it is at the home page. Accessing the product from the home page, the link is something like "/square-grate.html".   If I enable the category link (going into settings> Catalog> Insert Category of Products in URLs ), I get the following links: "/square-grate.html" - by accessing from home page "cast-iron/square-grate.html" - by accessing from the category page cast iron "cast-iron/grates/square-grate.html" - by accessing the cast iron category , then the subcategory grates   Just what my client need is that all the above examples urls are the "/cast-iron/square-grate.html" does someone has any hint how can I do that?

Maybe changing .htacess or some php script, but I don't have any idea how to do that.

  • 写回答

2条回答 默认 最新

  • doumang20060820 2014-01-27 02:39
    关注

    Using Magento's canonical feature will be the easiest way to resolve this problem. The only downfall is it won't include the category names and may miss out on additional keywords in the URL. Developing or purchasing a module is the next best way if you have the programming skills or budget to do so. If you're on a limited budget, you may get able to get away without spending any money if you're comfortable doing some modifications and data entry/database import.

    I'm not a very good programmer but I got around this adding a new attribute, say canonical_category. Before Magento 1.8, I was able to override the $categoryid with a new value based on the category IDs. For instance, whatever I wanted to set as the canonical link, I would just enter a number in the new attribute field and it would generate a link with that category.

    Magento 1.8 is slightly different, as they looked like they updated that section. Unfortunately I can't look at it now and tell you how to get the same functionality, but I quickly went through the new code and put together a workaround in case it may help you.

    The file that needs to be modified is /app/code/core/Mage/Catalog/Model/Product/Url.php. On line 267 we'll find the code that handles the canonical link, function _getProductUrl. Basically we're going to use the canonical_category value if available and just fallback on the original code if nothing is entered.

    So we'll change this line of code:

    if (!empty($requestPath)) {
        return $this->getUrlInstance()->getDirectUrl($requestPath, $routeParams);
    }
    

    to

    if (!empty($requestPath)) {         
            if($product->getCanonicalCategory()) {
                return $this->getUrlInstance()->getDirectUrl($product->getCanonicalCategory());
            } else {
                return $this->getUrlInstance()->getDirectUrl($requestPath, $routeParams);
            }
        }
    

    Just to be clear, all this will do is let you specify what you want your canonical link to be, in your case you want to include the category name. Your links to the product page will still appear to be the same (square-grate.html, /cast-iron/square-grate.html) but from what I understand the search engines will still treat this as the same page as long as a canonical link is specified. This should resolve the SEO issue but now there is more work if you want a specific link to be used. I can tell you any method that is not done dynamically is not the best way, but it will work and you can update/generate links easily via spreadsheet and database import. You can also just use it on products that need to include the additional [category] keywords. Note that the URL that is entered for the attribute should be relative (ie "cast-iron/square-grate.html"). Hopefully this helps.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 phython读取excel表格报错 ^7个 SyntaxError: invalid syntax 语句报错
  • ¥20 @microsoft/fetch-event-source 流式响应问题
  • ¥15 ogg dd trandata 报错
  • ¥15 高缺失率数据如何选择填充方式
  • ¥50 potsgresql15备份问题
  • ¥15 Mac系统vs code使用phpstudy如何配置debug来调试php
  • ¥15 目前主流的音乐软件,像网易云音乐,QQ音乐他们的前端和后台部分是用的什么技术实现的?求解!
  • ¥60 pb数据库修改与连接
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?