Keyword

SEF Category URL prefix

  • Geraldo de Oliveira
  • Geraldo de Oliveira's Avatar Topic Author
  • Offline
  • New Member
More
4 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
4 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

Fotis / JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)

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

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

Fotis / JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)

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
4 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
4 years 4 months ago - 4 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.

Fotis / JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Last edit: 4 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
4 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
4 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.

Fotis / JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)

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

Fotis / JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)

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

More
4 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.

Fotis / JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)

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


Powered by Kunena Forum