User tests: Successful: Unsuccessful:
This Pull Request is related to issues #9333 and #9556.
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.
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
Status | New | ⇒ | Pending |
Labels |
Added:
?
|
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
@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.
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.
I doubt about the utility of such a feature but it works as it indeed displays the full url.
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.
I suggest you clean your caches.
@infograf768 actually the canonical is being added.
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&type=rss" rel="alternate" type="application/rss+xml" title="RSS 2.0" />
<link href="/trunkgitnew/?format=feed&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&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">
[...]
About intended / designed behaviour:
the "calculated" canonical URL
that is the intended behaviour, right ?
Yes, according to Hackwar, canonical URL should be added only on non-canonical pages. E.g. when accessing through non-SEF URL.
What Joomla does not have now is:
but an official way would be good
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.
Google guidelines (last time i read them) say when canonical is same as current page URL
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
This would change the purpose of the plugin. But perhaps it is better to have no canonical than a wrong canonical for now.
This would change the purpose of the plugin.
Why?
Because it would no longer add the canonical on non-canonical pages. Which is OK considering currently the canonicals are mostly incorrect.
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?
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.
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.
Status | Pending | ⇒ | Closed |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2016-03-24 15:33:17 |
Closed_By | ⇒ | SharkyKZ |
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?