Setting canonical tags for categories in Magento

旧街凉风 提交于 2019-12-11 06:28:42

问题


Is this possible, or is there some code that can be added so I can set a different canonical URL for categories in Magento? I can set for products fine.


回答1:


Out of the box there is nothing for this that I am aware of. You will need to develop or build your own method of doing this.

You will need to create an entry in a layout.xml file to put an additional template in the head section of the page when you are on a category page (this would likely be in a catalog_Category_view block). You would also probably need a view file as well as a Block object to fetch the URL you want to use (technically you could put that in the view file, but having the block object is more "Magento").

Your layout.xml block would look something like this

<catalog_category_view>
    <reference name="head">
        <block type="canonical/canonical" name="head_url" as="head_url" template="ocaff/canonical/head.phtml" />
    </reference>
</catalog_category_view>

This block references a head.phtml file. That file would contain:

<link rel="canonical" href="<?php echo $this->getCanonicalUrl() ?>" />

This calls back to a block object that has a function called getCanonicalUrl(). In this function you will find and determine what you want the canonical to be. Most likely you want this to be the URL key, but you may have other logic in mind there.




回答2:


Just found this question while searching for info about canonical URL support.

I'm not sure which version added this (couldn't find anything in release notes), but it is now supported out of the box in 1.7.0.2.

In admin: SYSTEM >> CONFIG >> CATALOG >> SEARCH ENGINE OPTIMIZATION

Last two options enable canonical URLs for categories and products.




回答3:


Canonical urls for product and category pages are supported by Magento from 1.5

In admin: SYSTEM >> CONFIG >> CATALOG >> SEARCH ENGINE OPTIMIZATION



来源:https://stackoverflow.com/questions/10513295/setting-canonical-tags-for-categories-in-magento

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!