Hi,
on a default Joomla installation with K2 enabled, the sef plugin generates a wrong canonical URL for K2 articles (the alias is doubled in the url)
So the canonical URL of
http://www.site.com/k2-category/item/405-some-alias
will look like
http://www.site.com/k2-category/item/405-some-alias/405-some-alias
.
I digged deeper, $router->parse($uri)
in plugins/system/sef/sef.php:47
with an uri like
http://www.site.com/k2-category/item/405-some-alias
returns this object:
Array
(
[format] => html
[Itemid] => 827
[option] => com_k2
[view] => item
[task] => 405:some-alias
[id] => 405:some-alias
)
(so task and id both exist with the same values)
later in the file, $fakelink = 'index.php?' . http_build_query($parsed);
looks like this: index.php?format=html&Itemid=827&option=com_k2&view=item&task=405%3Asome-alias
... which gets transformed by $link = $domain . JRoute::_($fakelink, false);
to the wrong canonical url above.
This forum link suggests unset()
-ing $parsed['id']
when $parsed['option']==='com_k2' && $parsed['view']==='item'
as a workaround.
How do you think can this get fixed?
Yes, exactly same issue, canonical url contains the same wrong url described in the issue as social sharing buttons, with repetition of the name of item/id+name of item
though base and og:url contains the right url adress.
is there any solution ?
catastophic for my website i should put in production next week.
as I wrote, for now you can hack your way around the bug like this:
--- a/plugins/system/sef/sef.php
+++ b/plugins/system/sef/sef.php
@@ -45,6 +45,11 @@ class PlgSystemSef extends JPlugin
}
$parsed = $router->parse($uri);
+ if (isset($parsed['option']) && isset($parsed['view'])
+ && $parsed['option'] === 'com_k2' && $parsed['view'] === 'item'
+ && isset($parsed['id'])) {
+ unset($parsed['id']);
+ }
$fakelink = 'index.php?' . http_build_query($parsed);
$link = $domain . JRoute::_($fakelink, false);
But as @elinw already wrote on JoomlaCode tracker, this is not the right place to put such workarounds:
We're not going to put custom code for a specific non core extension in the core. Extensions either need to work with the core apis or provide their own work arounds. In this case you can just copy the core sef plugin, make your changes, install that and disable the core plugin. That's the advantage of a pluggable system. and perhaps the k2 team would distribute such a plugin.
K2 should provide a fix for this problem on its own. I don't know what exactly in K2 makes $router->parse($uri)
in plugins/system/sef/sef.php:47
return same "task" and "id" values.
This has been fixed on K2's repo. You can test our dev build from: http://getk2.org/assets/get/
Labels |
Added:
?
Removed: ? |
||
Build | ⇒ | staging |
So how it's fixed? which k2 version uses the fixed code so that there is no double tilte url?? or what code i need to change for this, i am using k2 v 2.6.6 in joomla 3
@mridulcs2012 please get in contact to the k2 developer. Thanks.
Just update to K2 v2.6.9 and you'll be fine.
On Nov 6, 2015 10:11 AM, "zero-24" notifications@github.com wrote:
@mridulcs2012 https://github.com/mridulcs2012 please get in contact to
the k2 developer. Thanks.—
Reply to this email directly or view it on GitHub
#2352 (comment).
Joomlacode issue: http://joomlacode.org/gf/project/joomla/tracker/?action=TrackerItemEdit&tracker_item_id=32442&start=0