Keyword

SEF Category URL prefix

  • Geraldo de Oliveira
  • Geraldo de Oliveira's Avatar Topic Author
  • Offline
  • New Member
More
5 years 4 months ago #174069 by Geraldo de Oliveira
SEF Category URL prefix was created by Geraldo de Oliveira
Hi everyone,
So, I bring a question that's bothering me for a while.

I would like to figure out how to completely disable the category prefix in K2's SEF Options.
Example, if I have an website that has a lot (I mean like 100-300) categories and that should be synced with an external database, I can't use the menu items and can't map the menu items. So I need to disable or change the routing for the categories without a menu item.

I find out the file required for the routing /com_k2/router.php, where in the array $segments are place some variables, including the Category Prefix in K2's SEF Options. I can edit that file and how the URL without the prefix but the actual URL without prefix doesn't work at all.

Like website.it/products/my-category/content/sub-category is the default URL.
I would like to have website.it/products/my-category/sub-category and I can achieve this editing the router.php file but the actual website.it/products/my-category/sub-category URL doesn't work and gives a 404 error.

Anyone ever suceeded in achieving this?

Thanks a lot a best regards!

Please Log in or Create an account to join the conversation.

More
5 years 4 months ago #174084 by JoomlaWorks
Replied by JoomlaWorks on topic SEF Category URL prefix
So, I've actually wanted to do this for some time now and this was a great occasion...

Grab the new router.php file I've uploaded here: jmp.sh/vG1WXii

Replace the current one and then do the following:
- Make sure there is at least 1 menu item pointing to all K2 categories. This could be your "products" menu or even the root menu item (home) of your site. Doing so will avoid duplicate URLs in Joomla as Joomla will know to "map" to K2 the new URL structure.
- Edit K2's Settings and change to the SEO tab, then scroll down to "Custom SEF URLs".
- In there, make sure that:
a) "Enable custom SEF settings for K2 URLs" is set to "Yes"
b) "Prefix for category URLs" is set to the string "empty" (this is important so we don't have to change the XML files of the component to unset the default values there for empty fields)
c) "Prefix for item URLs" is set to "Use the item's category"
d) "Use the item ID in the URL" is set to "No"
e) "Use the category ID in the URL" is set to "No"

Your settings there should look like this screenshot overall: jmp.sh/RoCBjqK

Clean your caches and check your site.

URLs for both categories and items will now be in the format:
domain.tld/root_menu_item_you_set/category_name/subcategory_name/another_subcategory_name/item_name

Please Log in or Create an account to join the conversation.

More
5 years 4 months ago #174088 by JoomlaWorks
Replied by JoomlaWorks on topic SEF Category URL prefix
I've now switched the demo site to the new router.

Here's an example URL on 3-level nested categories assigned to the "home" menu item: demo.getk2.org/magazine/design/architecture/morbi-adipiscing-sapien-non-tellus

If tests prove the new router to work as expected, I will adapt the default "Custom SEF" settings so you can get that layout just by enabling the top option and without having to configure the rest of the options (cause, frankly, few people would want more control over that).

Please Log in or Create an account to join the conversation.

  • Geraldo de Oliveira
  • Geraldo de Oliveira's Avatar Topic Author
  • Offline
  • New Member
More
5 years 4 months ago #174112 by Geraldo de Oliveira
Replied by Geraldo de Oliveira on topic SEF Category URL prefix
A.W.E.S.O.M.E.!! Thanks a lot Fotis! You're a master!

It pretty works but still having some problems, like:

1. I'm, having a a double all K2 Categories menu item slug in the path mizar.mediandmore.it/prodotti/prodotti/interni-incassi

2. It seems that the last categories that has a hypen in the alias returns a 404 error
This has a hypen mizar.mediandmore.it/prodotti/prodotti/interni-incassi/teatro-quadro
And this not mizar.mediandmore.it/prodotti/prodotti/interni-incassi/teatrotondo

Myself gonna try to figure it out today.

But really, really thanks! With this I think K2 wins hands down the most powerful tool in Joomla!

Please Log in or Create an account to join the conversation.

More
5 years 4 months ago - 5 years 4 months ago #174119 by JoomlaWorks
Replied by JoomlaWorks on topic SEF Category URL prefix
Thanks for the feedback.

1. I can only assume that you have a menu item with the alias "prodotti" pointing to a K2 (parent) category with the alias "prodotti" as well. Is that correct?

2. I think I know why this occurs. I'll update the code and get back to you.

I'm also planning on adding some sort of caching to the router for increased performance.
Last edit: 5 years 4 months ago by JoomlaWorks.

Please Log in or Create an account to join the conversation.

  • Geraldo de Oliveira
  • Geraldo de Oliveira's Avatar Topic Author
  • Offline
  • New Member
More
5 years 4 months ago #174125 by Geraldo de Oliveira
Replied by Geraldo de Oliveira on topic SEF Category URL prefix
Hi there,
Yes, I have a menu item "Prodotti" that is linked to the main K2 Category "Prodotti". I guess from somewhere I need to call the categories. But I could also use an article and call the categories by a module. But I think the "/prodotti/prodotti/" issue would still be there.

I'm trying a few things and I'll share in the forum soon.

Thanks again Fotis!

Please Log in or Create an account to join the conversation.

More
5 years 4 months ago #174128 by JoomlaWorks
Replied by JoomlaWorks on topic SEF Category URL prefix
Or you can edit the menu item and point it to link *directly* to the children of the K2 category "Prodotti" (and not to the parent category). Try that too and let me know.

Please Log in or Create an account to join the conversation.

  • Geraldo de Oliveira
  • Geraldo de Oliveira's Avatar Topic Author
  • Offline
  • New Member
More
5 years 4 months ago #174129 by Geraldo de Oliveira
Replied by Geraldo de Oliveira on topic SEF Category URL prefix
Mmm, sounds like a good idea but in this case I'll need to choose every category. It's fine if there's a few categories, but in this case I would have quite a few and also, in a near future, sub categories and items would be synchronized with a webserver.

But anyway, it doesn't work neither. I still have "prodotti/prodotti/" even if the menu item is set only to the children categories.

But honestly this is a minor problem. I can rename the parent category like "Model" and still maintain a nice URL and translation features.

I'll keep trying...

Please Log in or Create an account to join the conversation.

More
5 years 4 months ago #174132 by JoomlaWorks
Replied by JoomlaWorks on topic SEF Category URL prefix
What basically happens is that your menu structure for the Category "Prodotti" starts AFTER the menu item which also happens to be named "Prodotti". But, yes, with some tweaking you can get nice URLs for sure. Unfortunately, the requirement for at least one K2 menu item pointing to at least all categories in K2 is required to get these URLs, otherwise Joomla won't know where to route requests.

I'll keep you posted on the hyphen issue.

Please Log in or Create an account to join the conversation.

More
5 years 4 months ago #174135 by JoomlaWorks
Replied by JoomlaWorks on topic SEF Category URL prefix
Fixed the hyphen issue. Get the updated file from: jmp.sh/pCV9gLc

And let me know if you spot anything else.

Please Log in or Create an account to join the conversation.

More
5 years 4 months ago #174136 by JoomlaWorks
Replied by JoomlaWorks on topic SEF Category URL prefix

Please Log in or Create an account to join the conversation.

More
5 years 4 months ago #174137 by JoomlaWorks
Replied by JoomlaWorks on topic SEF Category URL prefix
I'm noticing the breadcrumbs option is di***** around so this will need to be addressed along with caching for the new router.

Please Log in or Create an account to join the conversation.

  • Geraldo de Oliveira
  • Geraldo de Oliveira's Avatar Topic Author
  • Offline
  • New Member
More
5 years 4 months ago #174138 by Geraldo de Oliveira
Replied by Geraldo de Oliveira on topic SEF Category URL prefix
Good morning Fotis,
Thanks again for the great work and help!

I've updated the router.php file and it works great! Everything is fine.

For the parent menu item I couldn't find any solution so I ended up naming parent category alias in another way so the URL are still functional and SEOlike.

Yes, the breadcrumb gone after the router.php updated. I've managed to created it my accessing the DB and getting the parent category name and routing the link. It seems to work
mizar.mediandmore.it/prodotti/modelli/interni-proiettori/risalto

So again, thanks a lot for the support!

Please Log in or Create an account to join the conversation.

More
5 years 4 months ago #174140 by JoomlaWorks
Replied by JoomlaWorks on topic SEF Category URL prefix
Great :)

Please Log in or Create an account to join the conversation.

More
5 years 4 months ago - 5 years 4 months ago #174210 by blue_Shift
Replied by blue_Shift on topic SEF Category URL prefix
I have followed above instructions, using a hidden menu for the root K2 category item - and everything looks good, except "/component/k2" still appears in the item. (see attached.)

Does webmaster tools / google analytics make use of these urls, or do we have have actual menu items for this to appear on submitted site maps?
Attachments:
Last edit: 5 years 4 months ago by blue_Shift. Reason: can't delete duplicate attachments. (the 'X' button or 'Remove All" didn't work.)

Please Log in or Create an account to join the conversation.

More
5 years 4 months ago #174213 by JoomlaWorks
Replied by JoomlaWorks on topic SEF Category URL prefix
First of all, install K2 v2.10.3 (dev) from github.com/getk2/k2/archive/master.zip which includes the latest code changes to the router.

Secondly, make sure "Custom SEF URLs" are enabled in K2's Settings (SEO tab).

Third, make sure there is at least 1 menu item pointing to all K2 Categories.

Finally, send me a URL to your site, especially a page that *includes* content with "component/k2" in their URLs.

Please Log in or Create an account to join the conversation.

More
5 years 4 months ago - 5 years 4 months ago #174214 by blue_Shift
Replied by blue_Shift on topic SEF Category URL prefix
if i set to the home page, I get a clean url - but the links go to the home page template (set in framework admin and assigned via menu parameters), not the default template (a variation set in the framework admin, built especially for the K2 item pages)

link to site: bit.ly/38XOkXn

ADDED: click on the content item in the row of images below the banner. (The category will produce 404, the item will produce a 'component/k2').
Attachments:
Last edit: 5 years 4 months ago by blue_Shift. Reason: added image, then added a reference to your third instruction...ok *fourth* instruction.

Please Log in or Create an account to join the conversation.

More
5 years 4 months ago - 5 years 4 months ago #174215 by blue_Shift
Replied by blue_Shift on topic SEF Category URL prefix
This image shows the 'empty' is in the url string - probably where the 404 is coming from.

edit: the last item in the menu bar is the link to all k2 categories.
Attachments:
Last edit: 5 years 4 months ago by blue_Shift. Reason: added tech. note about the menu item

Please Log in or Create an account to join the conversation.

More
5 years 4 months ago #174221 by JoomlaWorks
Replied by JoomlaWorks on topic SEF Category URL prefix
There is no need to use "empty" anymore, it was a temporary hack for Alberto to test things out without doing changes to the XML files. So just delete it.

Additionally, upgrade to K2 v2.10.3 (dev) again as new changes have been merged since the copy you installed (cause the SEO settings order had changed and I can see you still use an older version).

As for why the template of the homepage is displayed everywhere when you assign it to all K2 categories, this is normal. It's because every K2 content on the homepage "carries" the itemid of the home menu item. As such, Joomla considers that you're still on the homepage, even though you navigate to different content.

But rest assured, I'm already working on a way to have a clean URL path, without duplicate entries. E.g. if you currently create a menu item called "blog" pointing to a single K2 category also called "blog", then the path to items will be /blog/blog/whatever, which is normal cause it's essentially /menu-item-alias/category-alias/item-alias.

As for the items with /component/k2, I'm guessing these come from a 3rd party module and not e.g. K2 Content (mod_k2_content). That module does not properly parse K2 URLs from "JRoute" AND "K2HelperRoute" (see for example: github.com/getk2/k2/blob/master/modules/mod_k2_content/helper.php#L286). Just inform its developers to update their code.

Please Log in or Create an account to join the conversation.

More
5 years 4 months ago #174222 by blue_Shift
Replied by blue_Shift on topic SEF Category URL prefix
Thanks, Fotis. The developer has been notified.

(I did install the new version, but perhaps I need to remove the manually-created router.php from one of the earlier posts? uninstall / reinstall?)

Using a hidden menu item - or as in my demo, using a menu item to link all K2 items should work in terms of getting it to a different template variation? It seems that it will work.

Once I have this sorted I can steer this project away from weirdpress.

Please Log in or Create an account to join the conversation.


Powered by Kunena Forum