?
avatar addondev
addondev
7 Mar 2016

Steps to reproduce the issue

https://www.joomla.org/core-features.html?blablabla

Expected result

<link href="https://www.joomla.org/core-features.html" rel="canonical" />

Actual result

<link href="https://www.joomla.org/core-features.html?blablabla=" rel="canonical" />

System information (as much as possible)

Wrong canonical link for pages with GET parameters.

Additional comments

This is a reason for content duplicate.

avatar addondev addondev - open - 7 Mar 2016
avatar richard67
richard67 - comment - 7 Mar 2016

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.

avatar brianteeman brianteeman - change - 7 Mar 2016
Category Router / SEF
avatar brianteeman brianteeman - change - 7 Mar 2016
Labels Added: ?
avatar SharkyKZ
SharkyKZ - comment - 8 Mar 2016

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.

avatar infograf768
infograf768 - comment - 8 Mar 2016

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."

avatar SharkyKZ
SharkyKZ - comment - 8 Mar 2016

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.

avatar richard67
richard67 - comment - 8 Mar 2016

There are 3rd party plugins you can find on JED (Joomla! Extensions Directory).

avatar infograf768 infograf768 - change - 9 Mar 2016
Status New Closed
Closed_Date 0000-00-00 00:00:00 2016-03-09 05:57:46
Closed_By infograf768
avatar infograf768
infograf768 - comment - 9 Mar 2016

As explained, canonical in joomla core are only provided domain to domain.

Closing as not a bug.


This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/9333.

avatar infograf768
infograf768 - comment - 9 Mar 2016
avatar joomla-cms-bot joomla-cms-bot - close - 9 Mar 2016
avatar joomla-cms-bot joomla-cms-bot - close - 9 Mar 2016
avatar ggppdk
ggppdk - comment - 9 Mar 2016

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

  • The redudant adding of it, is fixed in J3.5.0 beta but this bug it is not really the problem (see below)

Can the SEF plugin really create a real REL canonical ?

  • no unless the relevant data are prepared by the component controller or view itself
  • i mean like for Joomla 's view caching the component controller code is defining "safeurlparams" which are used by cache to create unique index

So similarly, i argue that the rel canonical should always set be set by the component's view (forget the modules ...)

  • which (= the component view or display task of controller) knows the proper rel canonical (and usually the URL variables that are relevant are the same as the "safeurlparams")

@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

Add a Comment

Login with GitHub to post a comment