Forcing Moodle 2.3 to work over SSL

When managing a Moodle site, there are reasons to make the entire Moodle site work on an https:// connection. This will make all data transmitted over the site to be encrypted on an SSL connection. To achieve this, the Moodle config.php file will need to be edited and the .htaccess will need to have a redirect set up to force the https:// to load. The following tutorial will explain how to force Moodle 2.3 to work over an SSL connection.

Forcing SSL on https for Moodle

  1. Log into cPanel
  2. force-ssl-1-non-moodle

    Navigate to the config.php file in the File manager.

    Look for the line 17 (on default config files) that shows:

    $CFG->wwwroot   = '';


    Change the https:// to https:// like the following:

    $CFG->wwwroot   = '';

  3. force-ssl-3-htaccess-moodle

    Next, Set up a redirect in your .htaccess file. Place the following code to force the https:// redirect.

    RewriteEngine On  RewriteCond %{SERVER_PORT} 80  RewriteRule ^(.*)$$1 [R,L]

    Save the .htaccess file.

This concludes the article on Forcing Moodle 2.3 to work over SSL. For more information on this Education course please visit Moodle site security and server settings

Alyssa Kordek Content Writer I

Alyssa started working for InMotion Hosting in 2015 as a member of the Technical Support team. Before being promoted to Technical Writer, Alyssa developed expertise in the fields of server hardware, Linux operating systems, cPanel, and WordPress. She now works to produce quality technical content featuring cutting-edge topics such as machine learning, data center infrastructure, and graphics card technology.

More Articles by Alyssa


  • Hi,

    your post is informative.

    In case if the moodle site is a subsite which is not a root site then how should the redirect code look like.


    • Hello Das,

      What do you mean a subsite? Did you mean a subdomain like ‘‘? If so, the SSL would need to have been created with that in mind. The code would be almost identical, simply replacing with

      Kindest Regards,
      Scott M

Leave a Reply to Das Cancel reply