Redirect to custom module/plugin

Redirect to custom module/plugin

by Hung Tran -
Number of replies: 5

On our site we try to override renderers if possible. However sometimes we need to create new modules and plugins which extend from core modules/plugins because we need to customize something in their libraries.

Because of this, we need to let users access to the custom ones instead of the core ones.

For example, instead of viewing the core forum oursite.com/mod/forum/view.php?id=3, we need to users to view the custom one oursite.com/mod/custom-forum/view.php?id=3.

This is not an easy job because we need to search the change the URL 'mod/forum' in many places in Moodle, which leads to customize other modules and plugins.

We think of redirecting users from the core modules/plugins to the custom ones. So if they access oursite.com/mod/forum/view.php?id=3 they are redirected to oursite.com/mod/custom-forum/view.php?id=3. However, we can't find a plugin event which helps us redirect as soon as the page is initialized.


I appreciate any suggestions to solve this. Thanks!

Average of ratings: -
In reply to Hung Tran

Re: Redirect to custom module/plugin

by Davo Smith -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

You definitely don't want to be redirecting inside event handlers - that could lead to all sorts of unexpected behaviour (e.g. modules that expect to do further processing after triggering the event, other event handlers expecting to process that event).

If you are wanting a straight mapping for [url].../forum/... to [url].../custom-forum/... then that sounds like a job for mod_rewrite on your server.

In reply to Hung Tran

Re: Redirect to custom module/plugin

by Michael Milette -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators

Hi Hung,

What kind of web server are you using?

As Davo mentioned, doing consistent redirections of this kind is probably easiest if you use something like Apache's mod_rewrite. If you are indeed using Apache, you can probably do this from the .htaccess file in the webroot of your Moodle site. If you are using another web server like NGINX or IIS, the configuration steps will be different.

Best regards,

Michael

In reply to Michael Milette

Re: Redirect to custom module/plugin

by Hung Tran -

Hi Davo and Michael,

Thank you for your replies! We thought of using mod_rewrite but it is our last choice. We are looking for a way which is more user friendly, the administrators are not technical users so we would like to create some configuration options in Moodle's admin so that they can manage the redirects easily.

Regards,
Hung

In reply to Hung Tran

Re: Redirect to custom module/plugin

by Olumuyiwa Taiwo -
Picture of Plugin developers

Have you looked into using customised scripts -- https://docs.moodle.org/dev/customscripts

Average of ratings: Useful (1)
In reply to Olumuyiwa Taiwo

Re: Redirect to custom module/plugin

by Hung Tran -

Hi Olumuyiwa,

Thank you for your reply! I didn't know about this ability. I will check it out definitely.

Regards,

Hung