Affects Version/s: 3.1.13, 3.3.7, 3.4.4, 3.5.1
Fix Version/s: None
With this ticket I'm hoping to reach consensus on what, if anything, Moodle can do to simplify multi-tenancy of a single Moodle instance operating across multiple domains or subdomains. I appreciate that this isn't currently a supported configuration and that there may be technical reasons that this is the case.
- Sharing a single Moodle deployment (shared source, database and cache) for use by multiple tenants.
- Providing access to a Moodle platform via different addresses (e.g. a school providing separate WAN/LAN configurations).
In this case you may set $CFG->wwwroot along the lines of the following, allowing dynamic assignment based on the contents of the request. Note that there's a need to validate the supplied Host header in the server configuration!
For the most part Moodle behaves "correctly" in this scenario, generating URLs relative to the provided wwwroot. Problems occur when wwwroot values appear in the content. For instance, an editing teacher logged in at the platform's canonical URL (https://demo.moodle.org) may create a URL activity pointing to another course on the platform (e.g. https://demo.moodle.org/course/view.php?id=123). A student logged into the platform from https://academy.acmecorp.com/ may follow this link and find themselves being prompted to log in on a domain they don't recognise as their session was only valid for demo.moodle.org.
- Add a generic wwwroot placeholder to moodle_url and some utility methods. I've modelled this after the existing pluginfile code (e.g. file_rewrite_pluginfile_urls().
- In modinfolib, replace references to the wwwroot placeholder with the active wwwroot.
- For the URL resource, filter the wwwroot from the externalurl value on its way into the database and on its way back out.
- For the LTI activity and page, resource and URL activities, ensure *_get_coursemodule_info() returns an onclick parameter with the wwwroot placeholder.
- What should happen for URL resources during backup and restore? Leaving the @@WWWROOT@@ placeholders in the URLs doesn't seem like an option for backwards compatibility. It looks as though we store original_wwwroot in backup_main_structure_step->define_structure(). Do we rewrite and store URLs in this form for rewriting on restore?