HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.
Turn discussion name to discussion id
tennyy
New
Hi, how can I change the discussion name to discussion id like below.
https://xxx.com/discussion/12/NAME#latest to https://xxx.com/discussion/DISCUSSION-ID#latest
I created my forum in chinese, so the link will be like this
(Vanilla 3.3)
0
Comments
Depending on where you want to change it, the solution might be to simply create a file /conf/bootstrap.before.php with the following content:
While that should be perfectly okay, it would be cleaner to create a plugin for that. You would have to create a plugin with an emply plugin class and add that function below the class definition.
You are great!
BTW, how to change the text "discussion" of permalink to other text like thread?
Thanks again.
I spy with my little lens
No luck with this treatment.☹️ It cause Page Not Found
That needs an additional route set up like it is described here
https://open.vanillaforums.com/discussion/31488/how-to-make-short-discussion-urls-for-vanilla
It seems not working.
Blind copy and paste without understanding oftentimes do not yield the expected results... As the above linked discussion explains, that route makes a "/discussion/123" available as "/d/123". Why did you expect it also makes a discussion available as "/thread/123"?
You should have put some brainwork in that. But hey, this is a help forum so here is the brainwork already done for you: that is the expression that you need
^thread/([\d]*)
Thank again.😅
The example I show to you was a brand new forum that I just created.
I replaced both "d" to "thread" on my live forum but still no luck.
I saw you taught me change to ^thread/([\d]*) and then I try it seems successful.
But when I clicked the topic the url bar changed to /discussion/ instead of / thread/ like https://xxx.com/discussion/12#latest
Thanks for your patient!
The route is a regular expression where "\d" is for decimal numbers (which is the discussion id in this case)
Depending on where you want to change it, the solution might be ...
The route simply is a redirection from the (technically) false "thread" or "d" or whatever to the (in Vanilla terms) correct "discussion". Changing this real address is way more complicated and might not even be possible.
My approach would be to create a ThreadController that extends the DiscussionController and try to hook somewhere in the dispatcher to call the ThreatController which then needs to intercept the request and re-route calls to the DiscussionController, but I would expect numerous problems with that.
Noted and thanks!
@tennyy While I delay in making the super plugin for Vanilla to manage Urls like a Boss, you can get some deep ideas from here
https://open.vanillaforums.com/discussion/37610/can-i-replace-functions-in-class-dispatcher-php#latest