General developer forum

Redirect to custom module/plugin

 
Picture of Hung Tran
Redirect to custom module/plugin
 

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: -
Davo
Re: Redirect to custom module/plugin
Group Core developersGroup Particularly helpful MoodlersGroup 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.

 
Average of ratings: -
Picture of Michael Milette
Re: Redirect to custom module/plugin
Group Core developersGroup Particularly helpful MoodlersGroup Plugin developers

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

 
Average of ratings: -
Picture of Hung Tran
Re: Redirect to custom module/plugin
 

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

 
Average of ratings: -
Picture of Olumuyiwa Taiwo
Re: Redirect to custom module/plugin
Group Particularly helpful Moodlers

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

 
Average of ratings: Useful (1)
Picture of Hung Tran
Re: Redirect to custom module/plugin
 

Hi Olumuyiwa,

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

Regards,

Hung

 
Average of ratings: -