https://www.joomla.org/core-features.html?blablabla
<link href="https://www.joomla.org/core-features.html" rel="canonical" />
<link href="https://www.joomla.org/core-features.html?blablabla=" rel="canonical" />
Wrong canonical link for pages with GET parameters.
This is a reason for content duplicate.
Category | ⇒ | Router / SEF |
Labels |
Added:
?
|
Canonicals are completely broken at the moment. Hackwar's recommendation regarding this is to test the new router since it's supposed to solve some of the duplicate content issues.
For now there isn't much that can be done without massive changes, I think. Currently, canonical URLs are generated by SEF plugin like so:
JRoute::_('index.php?' . http_build_query($this->app->getRouter()->getVars()), false)
This means it just takes all URL parameters provided, routes (incorrectly in some cases) whatever is possible and appends everything else. As you can guess, this doesn't work at all for the purpose it's meant to.
What the SEF plugin is only doing is writing a canonical IF another domain is entered in the field.
It was never designed to do anything else and was NOT even working until recently patched for 3.5.0.
PLG_SEF_DOMAIN_DESCRIPTION="If your site can be accessed through more than one domain enter the canonical one here."
That makes it more clear. So besides canonical domain there are no canonical URLs in Joomla.
Are there any plans to add them? Currently, ComponentHelperRoute seems to create correct canonical URLs and strip junk parameters.
There are 3rd party plugins you can find on JED (Joomla! Extensions Directory).
Status | New | ⇒ | Closed |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2016-03-09 05:57:46 |
Closed_By | ⇒ | infograf768 |
As explained, canonical in joomla core are only provided domain to domain.
Closing as not a bug.
Set to "closed" on behalf of @infograf768 by The JTracker Application at issues.joomla.org/joomla-cms/9333
The rel canonical that is added by SEF plugin is just a "default" one, and in J3.4.x under some configurations, it is added despite being same with current URL
Can the SEF plugin really create a real REL canonical ?
So similarly, i argue that the rel canonical should always set be set by the component's view (forget the modules ...)
@addondev
If the rel canonical added by SEF plugin is not good for your component view then you can set it like this:
$uri = JUri::getInstance();
$doc = JFactory::getDocument();
// The canonical must be decided by the VIEW which knows which URLs are same
$ucanonical = ... DECIDE YOUR canonical
// Get the domain configured in SEF plugin (multi-domain website)
$plugin = JPluginHelper::getPlugin('system', 'sef');
$pluginParams = new JRegistry($plugin ? $plugin->params : null);
$domain = $pluginParams->get('domain');
$domain = $domain ? $domain : $uri->toString(array('scheme', 'host', 'port'));
// Encode the canonical URL
$ucanonical = $domain . $ucanonical;
$ucanonical_encoded = htmlspecialchars($ucanonical);
// Get head object
$head_obj = $doc->mergeHeadData(array(1=>1));
// Remove canonical inserted by SEF plugin, unsetting default directly may not be reliable
// as code of SEF plugin may change, the following costs almost zero anyway
$addRel = true;
foreach($head_obj->_links as $link => $data)
{
if ($data['relation']=='canonical' && $data['relType']=='rel') {
if($link == $ucanonical_encoded)
$addRel = false;
else
unset($head_obj->_links[$link]);
}
}
// Add REL canonical only if different than current URL
if ($addRel && rawurldecode($uri->toString()) != $ucanonical)
{
$doc->addHeadLink( $ucanonical_encoded, 'canonical', 'rel' );
}
I argue that the code for rel canonical must be moved to the component's view (or by display task of controller) like similarly that the component's controller decides which page is unique by setting SAFEURLPARAMS
with the above i suggest update core components code too, to have appropriate code to decide rel canonical
Joomla! cannot really know if this parameter causes different content or not.
For this purpose, the popular search engines (Google, Bing, ...) provide administrator pages where you can set up which url parameters to be ignored or not.
So from my user point of view (I am not a Joomla! maintainer) I would say this here is not an issue.
This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/9333.