Save the template file and upload it to your webserver.
Test the code by going to your home page and viewing the page source. You should see the <link rel=”canonical” href=”http://mysite.com” /> between the head tags.
Next, go to any page other than the home page, and inspect the page code. You should not see the canonical url between the head tags.
@Pat Fortino “Currently, there are no extensions for Joomla that add a canonical link to your pages”
This isn’t true. I’ve been using a canonicalization app on all of my Joomla 2.5 sites for at least the last year. Further, a quick Google search returns two different extensions, at least.
I’m not talking about domain name canonization. I’m talking about the canonical url that needs to be written on each unique page so you can avoid duplicate content. There are no joomla extensions that do this.
Jordan D.says
I don’t know man… There’s a category of extension called “URL Canonicalization.”
I spot checked one of the sites I run, http://www.morphisinc.com, by clicking on random links in the top menu and then viewing the page source. All of them had rel=canonical with the appropriate URL.
What I wasn’t able to find was a non-canonical version of a page that didn’t redirect to a canonical version, but I thought about it and I didn’t see how the extension would accomplish this given the information it was given. I suspect that it just puts the tag on every page which kind of janky.
I like your fix though. Do you know of any reason why one wouldn’t be able to make an extension based on this fix?
I think you can use a sef extension like sh404sef to write cannonical urls for each page, but there are no extensions that do it automatically. Having to write each one manually would be a major pain if you have 100s of pages.
Jordan D. says
@Pat Fortino “Currently, there are no extensions for Joomla that add a canonical link to your pages”
This isn’t true. I’ve been using a canonicalization app on all of my Joomla 2.5 sites for at least the last year. Further, a quick Google search returns two different extensions, at least.
This one has 4.94/5.0
http://extensions.joomla.org/extensions/site-management/seo-a-metadata/url-canonicalization-/5355
Here’s another one for multi-language sites:
http://extensions.joomla.org/extensions/site-management/seo-a-metadata/url-canonicalization-/19802
Pat Fortino says
I’m not talking about domain name canonization. I’m talking about the canonical url that needs to be written on each unique page so you can avoid duplicate content. There are no joomla extensions that do this.
Jordan D. says
I don’t know man… There’s a category of extension called “URL Canonicalization.”
index.php?option=com_content&view=article&id=199:dispatch-monitor-and-report&catid=64:field-service-management&Itemid=498
I spot checked one of the sites I run, http://www.morphisinc.com, by clicking on random links in the top menu and then viewing the page source. All of them had rel=canonical with the appropriate URL.
What I wasn’t able to find was a non-canonical version of a page that didn’t redirect to a canonical version, but I thought about it and I didn’t see how the extension would accomplish this given the information it was given. I suspect that it just puts the tag on every page which kind of janky.
I like your fix though. Do you know of any reason why one wouldn’t be able to make an extension based on this fix?
Pat Fortino says
I think you can use a sef extension like sh404sef to write cannonical urls for each page, but there are no extensions that do it automatically. Having to write each one manually would be a major pain if you have 100s of pages.
Andy says
Ich habe unter http://stackoverflow.com/questions/14147627/get-active-menu-url/14171745? eine Frage nach einer ein wenig erweiterten Version eröffnet. Eventuell hat hier jemand eine Idee?
calvin says
I dont want this on just my home page – your solution only works for that.
If a age is internal say site.com/page1
then I would like the code to be
canonurl=site.com/section1/page1
even if the page is found by inserting ignored junk (like crawling seems able to do)
site.com/I-am-ignored-junk/section1/page1
I still want the same canon url to be displayed as
!!!!!!! canonurl=site.com/section1/page1 !!!!!!!
, but what is the joomla framework php that will give me the right URL !