Something simple like this in the main template:
<link rel="canonical" href="http://www.example.com/[*alias*]" />
?
@dev_cw: Yes or [~[*id*]~] can return alias by mod_rewrite if I get this thing right:
http://www.webmasterworld.com/forum30/28332.htm
I’m working with friendly URLs so using the alias won’t work.
From the suggestion of mrhaw, I created a text TV (named originalPage) with default value [tt][~[*id*]~][/tt] and added [tt]<link rel="canonical" href="[*originalPage*]"/>[/tt] to the template.
So whenever the page is to be canonicalized, it’s sufficient to write the link to the original one in the TV value form (eg, [tt][~34~][/tt]). And for original pages, nothing needs to be done.
This approach is friendly-urls-friendly, as the generated link is then parsed by MODx.
Thanks!
João
I was referring to a built in tv:
http://modxcms.com/document-tvs.html
But your approach works for sure!
OK, I just had a go at the snippet mentioned by dev_cw, but it is not working for me.
Probably completely misunderstand how to do this, but if someone could point out how to do it, I’d appreciate it.
Created snippet canonical
<?php
$alias = $modx->documentObject[alias];
// if alias blank use the docid
if ($alias != "") {
$output = $modx->documentObject[alias];
} else {
$output = $modx->documentObject[id];
}
return $output
?>
Then I put
<link rel="canonical" href="[(site_url)][[canonical]].html" />
in the template