? Success

User tests: Successful: Unsuccessful:

avatar SharkyKZ
SharkyKZ
24 Mar 2016

This Pull Request is related to issues #9333 and #9556.

Summary of Changes

As per @ggppdk's comment on #9333, canonical generated by SEF plugin is a generic canonical for Joomla!. It is used not only when a canonical domain is specified in SEF plugin params. Therefore, it should be made absolute even if no domain is specified.

Testing Instructions

  1. With no domain set in SEF plugin, go to a non-canonical page on Joomla where canonical URL is generated by SEF plugin.
  2. Check canonical URL of the page, it is relative (does not include domain).
  3. Apply patch.
  4. Canonical URL should now be absolute (includes domain).

Note: This doesn't fix canonical URL behavior fully, only makes URLs absolute as per Google's recommendation: https://support.google.com/webmasters/answer/139066?hl=en

avatar SharkyKZ SharkyKZ - open - 24 Mar 2016
avatar SharkyKZ SharkyKZ - change - 24 Mar 2016
Status New Pending
avatar joomla-cms-bot joomla-cms-bot - change - 24 Mar 2016
Labels Added: ?
avatar chivitli
chivitli - comment - 24 Mar 2016

I am not sure what is the correct behaviour here, because @infograf768 says that canonicals should be added only if the domain field is filled in? So should canonicals be always added in Joomla SEF, or only when this field is filled in?

avatar infograf768
infograf768 - comment - 24 Mar 2016

I have explained in details how this works in Joomla with the SEF plugin... There is no other way to get a canonical with Core

avatar SharkyKZ
SharkyKZ - comment - 24 Mar 2016

@infograf768, you are incorrect there. SEF plugin is (currently) meant to add canonical URLs on non-canonical pages. This is correctly explained by @Hackwar on #6217 and @ggppdk on #9333. Canonical domain is a separate feature and not related to these issues.

Now, from what they said we should understand that SEF plugin at the moment can't create accurate canonical URLs and that's OK here, this PR doesn't try to fix anything like that. It just changes the already added canonical URLs from relative to absolute to comply with Google.

avatar infograf768
infograf768 - comment - 24 Mar 2016

You just have to enter the full url in the SEF field:

Here is what I get:
<link href="http://otherdomain.com/testwindows/trunkgitnew/" rel="canonical" />

when I entered http://otherdomain.com as other domain

Evidently the structure of the other domain has to be the same as the one you use the plugin in.

screen shot 2016-03-24 at 10 18 05

I doubt about the utility of such a feature but it works as it indeed displays the full url.

avatar SharkyKZ
SharkyKZ - comment - 24 Mar 2016

Like said before, canonical domain parameter is an optional feature. Canonical link is added on non-canonical pages regardless of whether domain is set in the plugin or not. The problem is that in case no domain is set, relative URLs are used instead of absolute. This is the only thing this PR is meant to change.

avatar infograf768
infograf768 - comment - 24 Mar 2016

The canonical link is NOT added here when the Field is empty. This was solved in 3.5 by:
b6d1e82

avatar infograf768
infograf768 - comment - 24 Mar 2016

I suggest you clean your caches.

avatar andrepereiradasilva
andrepereiradasilva - comment - 24 Mar 2016

@infograf768 actually the canonical is being added.

avatar infograf768
infograf768 - comment - 24 Mar 2016

Not here:

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-gb" lang="en-gb" dir="ltr">
<head>
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
      <meta charset="utf-8" />
  <base href="http://localhost:8888/trunkgitnew/" />
  <meta name="description" content="UNE DESCRIPTION" />
  <meta name="generator" content="Joomla! - Open Source Content Management" />
  <title>Home - My very long test site name</title>
  <link href="/trunkgitnew/?format=feed&amp;type=rss" rel="alternate" type="application/rss+xml" title="RSS 2.0" />
  <link href="/trunkgitnew/?format=feed&amp;type=atom" rel="alternate" type="application/atom+xml" title="Atom 1.0" />
  <link href="/trunkgitnew/templates/protostar/favicon.ico" rel="shortcut icon" type="image/vnd.microsoft.icon" />
  <link href="http://localhost:8888/trunkgitnew/component/search/?Itemid=435&amp;format=opensearch" rel="search" title="Search My very long test site name" type="application/opensearchdescription+xml" />
  <link rel="stylesheet" href="/trunkgitnew/templates/protostar/css/template.css" />
  <style type="text/css">
div.mod_search63 input[type="search"]{ width:auto; }
  </style>
  <script src="/trunkgitnew/media/jui/js/jquery.min.js"></script>
  <script src="/trunkgitnew/media/jui/js/jquery-noconflict.js"></script>
  <script src="/trunkgitnew/media/jui/js/jquery-migrate.min.js"></script>
  <script src="/trunkgitnew/media/system/js/caption.js"></script>
  <script src="/trunkgitnew/media/jui/js/bootstrap.min.js"></script>
  <script src="/trunkgitnew/templates/protostar/js/template.js"></script>
  <script src="/trunkgitnew/media/system/js/html5fallback.js"></script>
  <script type="text/javascript">
[...]
avatar ggppdk
ggppdk - comment - 24 Mar 2016

About intended / designed behaviour:

the "calculated" canonical URL

  • should not be added if it is -same- with current URL

that is the intended behaviour, right ?

avatar SharkyKZ
SharkyKZ - comment - 24 Mar 2016

Yes, according to Hackwar, canonical URL should be added only on non-canonical pages. E.g. when accessing through non-SEF URL.

avatar ggppdk
ggppdk - comment - 24 Mar 2016

What Joomla does not have now is:

  • an official way of how a component can remove the default canonical URL and add / decide on their own
  • i have suggested a sample code for developers of components to remove default canonical URL here: #9333 (comment)

but an official way would be good

avatar chivitli
chivitli - comment - 24 Mar 2016

@SharkyKZ @Hackwar

Canonical URL should actually be added to canonical pages as well. Google says: Mark up the canonical page and any other variants with a rel="canonical" link element.

avatar ggppdk
ggppdk - comment - 24 Mar 2016

Google guidelines (last time i read them) say when canonical is same as current page URL

  • then it can be skipped, but it also states that it will not do any harm to add it
avatar andrepereiradasilva
andrepereiradasilva - comment - 24 Mar 2016

ok, so this should solve it right?
This will only add canonical if the domain field in the plugin has some value.

    $domain = $this->params->get('domain', '');
    if ($domain !== '')
    {
        $uri    = JUri::getInstance();
        $link   = $domain . JRoute::_('index.php?' . http_build_query($this->app->getRouter()->getVars()), false);

        if (rawurldecode($uri->toString()) !== $link)
        {
            $doc->addHeadLink(htmlspecialchars($link), 'canonical');
        }
    }

In https://github.com/joomla/joomla-cms/blob/staging/plugins/system/sef/sef.php#L43-L56

can you guys test?

Updated the code

avatar SharkyKZ
SharkyKZ - comment - 24 Mar 2016

This would change the purpose of the plugin. But perhaps it is better to have no canonical than a wrong canonical for now.

avatar andrepereiradasilva
andrepereiradasilva - comment - 24 Mar 2016

This would change the purpose of the plugin.

Why?

avatar andrepereiradasilva
andrepereiradasilva - comment - 24 Mar 2016

Please test #9565

avatar SharkyKZ
SharkyKZ - comment - 24 Mar 2016

Because it would no longer add the canonical on non-canonical pages. Which is OK considering currently the canonicals are mostly incorrect.

avatar andrepereiradasilva
andrepereiradasilva - comment - 24 Mar 2016

Because it would no longer add the canonical on non-canonical pages. Which is OK considering currently the canonicals are mostly incorrect.

i could be wrong as i don't know the complete history here, but isn't the propose of the canonical functionality on the SEF plugin to add a canonical only when you set a different domain?

avatar SharkyKZ
SharkyKZ - comment - 24 Mar 2016

As stated in the referenced posts, no. When entering through non-canonical links (e.g. non-SEF), canonical is meant to be added. But at the moment canonicals are not routed properly. Which is why it's OK not to have them at all.

avatar SharkyKZ
SharkyKZ - comment - 24 Mar 2016

The path of current URL (taken with JUri::getInstance()) can be different than what is achieved with this:
JRoute::_('index.php?' . http_build_query($this->app->getRouter()->getVars()), false)
which is why canonicals are added as you can see in the plugin code.

avatar andrepereiradasilva
andrepereiradasilva - comment - 24 Mar 2016

@SharkyKZ if you agrre can this be closed and replaced by the other PR (#9565)?

avatar SharkyKZ
SharkyKZ - comment - 24 Mar 2016

Closed in favor of #9565.

avatar SharkyKZ SharkyKZ - change - 24 Mar 2016
Status Pending Closed
Closed_Date 0000-00-00 00:00:00 2016-03-24 15:33:17
Closed_By SharkyKZ
avatar SharkyKZ SharkyKZ - close - 24 Mar 2016

Add a Comment

Login with GitHub to post a comment