How to set up different URLs per tenant
Overview
Moodle will only allow you to use a single URL for the site (defined in the config.php file under CFG->wwwroot), and this is the setting used for the default URL for an IOMAD site. But what if you want to use self-signup and allow users to be automatically assigned to the correct company, or want the site branding to appear before a user is logged in?
In that case, the branding of an IOMAD site needs to be set up so it is presented to users before they are even logged in, allowing the company to already be specified, so things like self-signup will automatically put the user into the correct company.
There are two ways to set up individual URLs: simplified or elegant.
How to set up a simplified tenant URL
The simplified way is to pass some parameters to the login URL, which are used to identify the company. This takes the form of:
https://<URL>/login/index.php?id=&code=
So, if you have the company Total Training set up on your site (https://demo.iomad.org) that has a record in the database table mdl_company (or mdl_companies from IOMAD 5.1 onwards) with an id of 3 and a shortname of TT, the URL would be:
https://demo.iomad.org/login/index.php?id=3&code=TT
This would take the company branding and apply it to the login page. It would persist through to the signup page, and anyone who uses this URL to create an account would be automatically put into the Total Training company.
The problem with this is approach is that it requires the link to have parameters in it (which users may not know), meaning there is a lot of scope for human error.
How to set up an elegant tenant URL
The more elegant solution would be to set up a different URL for this company. This then means that the system knows what company to use, and you can dispense with the URL parameters. The steps for this are as follows:
- Set up a DNS entry for the new hostname you are going to use, which has the same A address or is a CNAME to your current site hostname.
- Set up the webserver to answer to this new hostname and use the same Document Root as for your current IOMAD site. Ensure that you have the same level of SSL certificate set up for this new domain as for the current IOMAD site, so if one is HTTPS, then all need to be HTTPS.
- Log into your IOMAD site, go to the IOMAD dashboard, select the company from the dropdown and click on Edit company under the Company tab.
- Open the Advanced company settings, add the new hostname into the hostname field and save.
NOTE: This is the hostname, not the URL. So if the URL is to be https://totaltraining.iomad.org then the hostname will be totaltraining.iomad.org only.
Now, if you open a new browser and navigate to the new URL, you will immediately be presented with the branding for Total Training before you log in. You can see this in action on the IOMAD demo site by using the pre-set URLs.