Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.
Remove "/categories" from permalink?
byakko
New
Hello, is there a way to change the permalink so that category pages can simply show without the "/categories" in the permalink?
IE. "www.forum.com/lounge" rather than "www.forum.com/categories/lounge"
I think this format is much simpler and the SEO isn't really a significant issue at this point (not as important as "/discussion/#/threadtitle").
Thank you!
Tagged:
0
Comments
It wouldn't be that easy. And what if someone decides to have a category called "discussions"? That would screw up the syntax.
True. It would also mess up links like /profile and /messages if they were in some case to be made categories as well. I'm still kind of curious on how to do so but of course will take precaution when managing categories and avoid conflicting URLs.
This might help you: http://vanillaforums.org/discussion/28400/how-to-change-category-slug-url
I think there is no real answer to your question but at least it is a start.
Thanks R_J
I managed to set the URL to www.forum.com/(categoryname) using the code below which changes all the links but the individual category pages still remain attached to www.forum.com/categories/(categoryname)
<?php if (!defined('APPLICATION')) exit(); function CategoryUrl($Category, $Page = '', $WithDomain = TRUE) { $Category = (object)$Category; //$Result = '/'.$Category->CategoryTitle.'/'.Gdn_Format::Url($Category->Name); $Result = '/'.Gdn_Format::Url($Category->Name); //no slug return Url($Result, $WithDomain); }
I've been trying to find something in application/vanilla that would allow me to actually remove "/categories" but still no luck.
Update: I tried adding a route with these settings:
Route: ^(.*)
Target: categories/$1
Type: Internal
Which DID successfully manage to change www.forum.com/categories/(categoryname) to www.forum.com/(categoryname)!
BUT the dashboard turns into a white page and the routing messes up other things.
Any thoughts?
I'm currently looking into the shortprofileUrls plugin (http://vanillaforums.org/addon/shortprofileurls-plugin) to see how they managed to do this. Not sure if it will be the same for categories though.
The error I receive when I set it to (.), ^(.), ^(.*)?$, etc. (I honestly have no clue how routes work so I'm just trial-and-error-ing.)
Fatal error: Allowed memory size of 268435456 bytes exhausted (tried to allocate 32 bytes) in /home/byakko/public_html/vanilla/library/core/class.dispatcher.php on line 632
Again, using this does manage to change the URL to my liking to www.forum/(categoryname) but it breaks the dashboard and other pages.
This is a good idea.
Search first
Check out the Documentation! We are always looking for new content and pull requests.
Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.
I GOT IT!!!
All I had to do was manually rout each category name. Didn't know it was that easy. All this time I was trying to use /categories/$1.
Target: /categories/name
Route: name
Type: Internal
Just do this for all of your categories and also remember to add bootstrap.after.php to your /conf redefining CategoryUrl() and you're all set
@byakko it is possible to dynamically route with a hook, something like (not tested):
You could even add the
CategoryUrl
function after the plugin class.grep is your friend.
The previous code I posted forgot page navigation, here's the correct one
<?php if (!defined('APPLICATION')) exit(); function CategoryUrl($Category, $Page = '', $WithDomain = TRUE) { $Category = (object)$Category; //$Result = '/'.$Category->CategoryTitle.'/'.Gdn_Format::Url($Category->Name); $Result = '/'.Gdn_Format::Url($Category->Name); //no slug if ($Page) { if ($Page > 1 || Gdn::Session()->UserID) $Result .= '/p'.$Page; } return Url($Result, $WithDomain); }
Correct routes are:
Route: name(.*)
Target: categories/name$1