How to Change Base URL Moodle based Web Application

Posted on

Introduction

This is an article where the main focus is to show how to change base URL of a web application running using Moodle framework. Basically, there is a situation where the running web application using Moodle framework has a requirement to change its own URL address. So, changing the URL address just like that apparently make the running web application cannot run anymore properly. The following is the error message appearance :

How to Change Base URL Moodle based Web Application
How to Change Base URL Moodle based Web Application

The change can be in any kind of forms. It can be a protocol access change from HTTP to HTTPS. But do not forget to check the article with the title of ‘How to Change Access Moodle-based Web Application from HTTP to HTTPS’ in this link. Because there is an additional configuration in the Moodle’s web application source code configuration in order to make the web application accept to run using HTTPS protocol.

 

Scenario

Actually, the scenario exist as follows which is actually a simple one :

How to Change Base URL Moodle based Web Application
How to Change Base URL Moodle based Web Application

The following is the explanation from the above image description describing the network schema.

  1. There is a running web application using Moodle framework. The current or the old URL address of the server where there is a web application running using Moodle framework is ‘http://www.mymoodlesites.com’.

  2. Apparently, there is a change request which is requiring to change the URL address of the server where there is a running web application which is using the Moodle framework. The new URL address of the server is  ‘http://www.mynewmoodlesites.com’.

  3. But upon the change address of the server, the web application running cannot display the web page anymore as it shown above.

Solution

There is a solution for solving the above error message. Actually, the solution is very simple. The following is the sequence of action in order to solve that message :

  1. Access the server.

  2. Go to the root folder of the Moodle’s based web application source code.

  3. Find the ‘config.php’ in that path. Open it and find the following part of the configuration source code :

    //=========================================================================
    // 2. WEB SITE LOCATION
    //=========================================================================
    // Now you need to tell Moodle where it is located. Specify the full
    // web address to where moodle has been installed. If your web site
    // is accessible via multiple URLs then choose the most natural one
    // that your students would use. Do not include a trailing slash
    //
    // If you need both intranet and Internet access please read
    // http://docs.moodle.org/en/masquerading
    
    $CFG->wwwroot = 'http://www.mymoodlesites.com/';
    
    
  4. Duplicate the last line, so there will be two exact same lines as follows :

    $CFG->wwwroot = 'http://www.mymoodlesites.com/';
    $CFG->wwwroot = 'http://www.mymoodlesites.com/';
    
  5. Comment the first line representing the old URL of the Moodle’s based web application as follows :

    // $CFG->wwwroot = 'http://www.mymoodlesites.com/';
    $CFG->wwwroot = 'http://www.mymoodlesites.com/';
    
  6. Change the last line which is representing the new URL of the Moodle’s based web application.

    // $CFG->wwwroot = 'http://www.mymoodlesites.com/';
    $CFG->wwwroot = 'http://www.mynewmoodlesites.com/';
    
  7. Do not forget to save the file. So, the following is the overall configuration part as exist in the config.php file :

    //=========================================================================
    // 2. WEB SITE LOCATION
    //=========================================================================
    // Now you need to tell Moodle where it is located. Specify the full
    // web address to where moodle has been installed. If your web site
    // is accessible via multiple URLs then choose the most natural one
    // that your students would use. Do not include a trailing slash
    //
    // If you need both intranet and Internet access please read
    // http://docs.moodle.org/en/masquerading
    
    // $CFG->wwwroot = 'http://www.mymoodlesites.com/';
    $CFG->wwwroot = 'http://www.mynewmoodlesites.com/';
    
  8. Finally, last but not least just try to access the Moodle’s based web application once more. If there are no other errors appear, it will display the normal Moodle’s web application page.

Leave a Reply