Question

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.

Était-ce utile?

La solution

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.

Autres conseils

the SEO thing is a known problem with magento. Due to the architecture and behaviour there are only 2 possible methods to get this wortking or at least reduce the symptoms. The first one is a Magento build-in setting which uses the canonical tags to hold the main url so google does not count subcategory productdetails page as dublicate content. You can set it under "System->Configuration->Catalog->Search Engine Optimizations" There you have the possibility to turn on Canonical Link Meta Tag for Categories and Products. The only half-good thing is, that it will use the upper Link as canonical... e.g. in your case the categories will not appear in the canonical url... only "/square-grate.html".

The second one is to spend some money and get a module which does all the needed rewriting for you. (I have programmed such a module which works like a charm on http://www.zoobox.de

Doing these things via .htaccess is a huge task as you have to react on any changes in the category AND productnames... and even on any change when a product is listed in another category... you will kill yourself when you reach 10 categories and 300 products ;) the other disadvantage of .htaccess is that apache will have to walk through the whole bunch of rewrites in .htaccess on any call to the server... if you have much rewrites in it this can be easy aroung 0.5 to 2MB size which will influence the performance somewhen... especially during heavy load phase...

If you need further assistance or are interested in the rewritingmodule, just let me know ;)

Cheers Ben

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top