Create Canonical Url In My Page

Hi,

I am developing a website where a page(category) has many subpages.I was advised that the proper implementation should consist of one main page and the rest should lead to canonical urls (supposedly google likes it that way). Has anybody implemented canonical urls with Yii and what design did you follow so they can be managed from backend. Any insiders would be highly appreciated.

Urls :

http://www.xxxx.com/category (Main Page)

http://www.xxxx.com/category/2 (Sub Page)

http://www.xxxx.com/category/3 (Sub Page)

http://www.xxxx.com/category/4 (Sub Page)

I would like to set the canonical url to my main page.

Hi

You could use UrlManager

http://www.yiiframework.com/doc/guide/1.1/en/topics.url

http://www.yiiframework.com/doc/api/1.1/CUrlManager

2,3,4 will be the id of the sub category

‘Canonical urls’ are not about url structure, they’re about avoiding duplicate content.

That is, if your content on urls

http://www.xxxx.com/category

and

http://www.xxxx.com/category/2

is not the same, you have nothing to worry about.

If for some reason content is the same, you should add

<link rel="canonical" href="http://www.xxxx.com/category" />

to all pages that are duplicates of http://www.xxxx.com/category

You are right ORey. Is there an extension through which I can add canonical URLs ?

Extension??

registerMetaTag should be enough…

Thanks ORey.

Found the solution :

Yii::app()->clientScript->registerLinkTag(‘canonical’, null, $href);