?
avatar flokli
flokli
27 Oct 2013

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?

avatar flokli flokli - open - 27 Oct 2013
avatar effidoc
effidoc - comment - 30 Oct 2013

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.

avatar flokli
flokli - comment - 31 Oct 2013

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.

avatar fevangelou
fevangelou - comment - 5 Nov 2013

This has been fixed on K2's repo. You can test our dev build from: http://getk2.org/assets/get/

avatar zero-24 zero-24 - close - 5 Nov 2013
avatar brianteeman brianteeman - close - 5 Nov 2013
avatar zero-24 zero-24 - change - 7 Jul 2015
Labels Added: ?
Removed: ?
Build staging
avatar mridulcs2012
mridulcs2012 - comment - 6 Nov 2015

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

avatar zero-24
zero-24 - comment - 6 Nov 2015

@mridulcs2012 please get in contact to the k2 developer. Thanks.

avatar fevangelou
fevangelou - comment - 6 Nov 2015

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

Add a Comment

Login with GitHub to post a comment