Forum Moderators: Robert Charlton & goodroi
[edited by: aakk9999 at 12:46 am (utc) on Nov 30, 2013]
[edit reason] Examplified URL [/edit]
http://www.example.com/town-st-1234-widget/page:1/sort:price/direction:desc http://www.example.com/town-st-1234-widget/?page=1&sort=price&direction=desc If you leave the parameters as parameters instead of rewriting them into a semi-pretty URL (we won't talk about the literal colons, ugh) it will be a lot easier to tell search engines which parts don't matter.
function SetCanon()
{
var theUrl = document.URL;
var iPos = theUrl.indexOf("sort:");
if (iPos != -1)
{
var theHead = document.getElementsByTagName("head")[0];
var strTmp = theUrl.slice(0, iPos - 1);
var eLink = document.createElement("link");
eLink.setAttribute("id", "Canon");
eLink.setAttribute("rel", "canonical");
eLink.setAttribute("href", strTmp);
theHead.appendChild(eLink);
}
}