Git Product home page Git Product logo

moodle-tool_redirects's Introduction

Configurable redirects for Moodle

A very simple plugin which allows admin to set redirects based on url. Redirects can be from existing Moodle pages like from one course to another, or they can be 'vanity' urls from non existing urls into a page inside Moodle.

Installation

Step 1: Install the local module

Using git submodule:

git submodule add [email protected]:catalyst/moodle-tool_redirects.git admin/tool/redirects

OR you can download as a zip from github

https://github.com/catalyst/moodle-tool_redirects/archive/master.zip

Extract this into /var/www/yourmoodle/admin/tool/redirects

Then run the moodle upgrade as normal.

https://docs.moodle.org/en/Installing_plugins

Step 2: Apply core patches

This plugin requires MDL-66340, which was added in 3.8.

You can easily backport these patches in one line for 3.5, 3.6 and 3.7:

For Moodle 3.5:

git apply --whitespace=nowarn admin/tool/redirects/patch/core35.diff

For Moodle 3.6:

git apply --whitespace=nowarn admin/tool/redirects/patch/core36.diff

For Moodle 3.7:

git apply --whitespace=nowarn admin/tool/redirects/patch/core37.diff

Manual cherry-pick

In case the patches do not work due to an update to older Moodle branches (such as security updates), you can manually perform the cherry-picks.

For MDL-66340:

git cherry-pick 4ed105a9fd4c37e063d384ff155bd10c3bfbb303

If there are merge conflicts, ensure the lines that you are adding are consistent with the lines being added inside the patch files. Everything else can safely be ignored.

Once this has been performed, you can generate your own patch files using git format-patch. An example for Moodle 3.5 is below:

git format-patch MOODLE_35_STABLE --stdout > admin/tool/redirects/patch/new_core35.diff

Configuration

  • Navigate to Site Administration > Plugins > Admin tools > Redirects
  • Add rules. Each line should be a redirect rule like [php regex of local moodle URL to redirect from]=>[any URL to redirect to]. E.g. #/my/#=>/course/view.php?id=2
  • Enable or disable redirects for administrators

If you wish to use redirects for urls which do not exist, eg /some-vanity-url then your webserver needs to be configured to have Moodle handle error pages. Setup details are here:

https://docs.moodle.org/dev/Error_pages

Backdoor option for Admins

Admins can bypass redirect by adding noredirect=1 parameter to requested URL. E.g. http://moodle.example.com/my/?noredirect=1

Contributing and Support

Issues, and pull requests using github are welcome and encouraged!

https://github.com/catalyst/moodle-tool_redirects/issues

If you would like commercial support or would like to sponsor additional improvements to this plugin please contact us:

https://www.catalyst-au.net/contact-us

Crafted by Catalyst IT

This plugin was developed by Catalyst IT Australia:

https://www.catalyst-au.net/

Catalyst IT

moodle-tool_redirects's People

Contributors

brendanheywood avatar dmitriim avatar golenkovm avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

moodle-tool_redirects's Issues

Have a debug mode for testing the regexes

If you are an admin and the checkbox for redirecting admin is not on, then instead of redirecting show an info notification saying what it would have normally done.

Cant make my rules to work

Hi... thanks for this great plugin!!!

Your example (/my/) works ok but i cant do it with my owns.

I need redict a course to another web in same site... and I wrote this:
/course/view.php?id=47=>/mod/scorm/view.php?id=748

The first part is a link on a button to access to a course (/course/view.php?id=47)
The second part is the activity itself inside that course (/mod/scorm/view.php?id=748)
I just want to bypass the sections part and go directly to de activity.

Thanks in advance!!!

Redirect from sources that are not Moodle URLs

Idea for an enhancement:

I would like to redirect with "vanity" - URLs, in order to make certain target URLs easier to get to directly.

Example:

#/importantquiz/#=>/mod/quiz/view.php?id=18

with the result being:
https://campus.mymoodlesite.com/importantquiz going to https://campus.mymoodlesite.com/mod/quiz/view.php?id=18

Could that functionality be added to the plugin? I would usually do this with redirect or ModRewrite in the .htaccess, but I would like to offer this possibility to admins in the GUI as well.

No redirects happening

I installed the plugin via zip-file on Moodle 3.9, and checked "redirect Admins". I entered:

/course/index.php?categoryid=120=>/local/dash/dashboard.php?id=2

(the target being a Dash-Dashboard, the link is valid)

But: nothing happens...

We are on nginx, otherwise I would have simply edited the .htaccess.

Allow comments anywhere in the textarea

This can be used after a redirect to comment on why it was added, or to comment out an entire regex

ideally done after #13 is implemented so we can use # as the comment character

PHP Notice during 3.7 -> 3.9 upgrade

With debugging on there is a PHP Notice thrown during moodle upgrade:

root@ca376e30acd9:/siteroot# php admin/cli/upgrade.php 
PHP Notice:  This page did not call $PAGE->set_url(...). Using * line 610 of /lib/pagelib.php: call to debugging()
* line 830 of /lib/pagelib.php: call to moodle_page->magic_get_url()
* line 107 of /admin/tool/redirects/classes/helper.php: call to moodle_page->__get()
* line 38 of /admin/tool/redirects/lib.php: call to tool_redirects\helper::redirect_from_rules()
* line 1054 of /lib/setup.php: call to tool_redirects_after_config()
* line 77 of /config.php: call to require_once()
* line 41 of /admin/cli/upgrade.php: call to require()
 in /siteroot/lib/weblib.php on line 3244
PHP Stack trace:
PHP   1. {main}() /siteroot/admin/cli/upgrade.php:0
PHP   2. require() /siteroot/admin/cli/upgrade.php:41
PHP   3. require_once() /siteroot/config.php:77
PHP   4. tool_redirects_after_config() /siteroot/lib/setup.php:1054
PHP   5. tool_redirects\helper::redirect_from_rules() /siteroot/admin/tool/redirects/lib.php:38
PHP   6. moodle_page->__get() /siteroot/admin/tool/redirects/classes/helper.php:107
PHP   7. moodle_page->magic_get_url() /siteroot/lib/pagelib.php:830
PHP   8. debugging() /siteroot/lib/pagelib.php:610
PHP   9. trigger_error() /siteroot/lib/weblib.php:3244
== Upgrading Moodle database from version 3.7.8 (Build: 20200914) (2019052008) to 3.9.2+ (Build: 20200929) (2020061502.03) ==

The plugin code used is the latest code (18b854d9).

prevent redirects when not logged into moodle

It would be good if the plugin prevents redirects if the user is not logged into moodle. The current behavior is that custom redirects are still applied even if you access the "redirect from" link in incognito where a user is not logged in.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.