COMMUNITY FORUM
SEF Category URL prefix
- Geraldo de Oliveira
-
Topic Author
- Offline
- New Member
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.
- JoomlaWorks
-
- Offline
- Admin
- Posts: 6227
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.
- JoomlaWorks
-
- Offline
- Admin
- Posts: 6227
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
-
Topic Author
- Offline
- New Member
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.
- JoomlaWorks
-
- Offline
- Admin
- Posts: 6227
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.
Please Log in or Create an account to join the conversation.
- Geraldo de Oliveira
-
Topic Author
- Offline
- New Member
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.
- JoomlaWorks
-
- Offline
- Admin
- Posts: 6227
Please Log in or Create an account to join the conversation.
- Geraldo de Oliveira
-
Topic Author
- Offline
- New Member
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.
- JoomlaWorks
-
- Offline
- Admin
- Posts: 6227
I'll keep you posted on the hyphen issue.
Please Log in or Create an account to join the conversation.
- JoomlaWorks
-
- Offline
- Admin
- Posts: 6227
And let me know if you spot anything else.
Please Log in or Create an account to join the conversation.
- JoomlaWorks
-
- Offline
- Admin
- Posts: 6227
Please Log in or Create an account to join the conversation.
- JoomlaWorks
-
- Offline
- Admin
- Posts: 6227
Please Log in or Create an account to join the conversation.
- Geraldo de Oliveira
-
Topic Author
- Offline
- New Member
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.
- JoomlaWorks
-
- Offline
- Admin
- Posts: 6227
Please Log in or Create an account to join the conversation.
- blue_Shift
-
- Offline
- Senior Member
- Posts: 44
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?
Please Log in or Create an account to join the conversation.
- JoomlaWorks
-
- Offline
- Admin
- Posts: 6227
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.
- blue_Shift
-
- Offline
- Senior Member
- Posts: 44
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').
Please Log in or Create an account to join the conversation.
- blue_Shift
-
- Offline
- Senior Member
- Posts: 44
edit: the last item in the menu bar is the link to all k2 categories.
Please Log in or Create an account to join the conversation.
- JoomlaWorks
-
- Offline
- Admin
- Posts: 6227
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.
- blue_Shift
-
- Offline
- Senior Member
- Posts: 44
(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.