Wednesday, October 1, 2014

Add static pages to your moodle (2.7)

To add static pages to your Moodle (2.7):

1. Install this plugin (Addon):

Github repo: https://github.com/moodleuulm/moodle-local_staticpage
Moodle plugin page: https://moodle.org/plugins/view.php?plugin=local_staticpage


2. Create a directory to store your static pages, by default it is:

/var/www/moodledata/staticpage

set the correct permission for that folder:

$ sudo chown -R www-data:www-data /var/www/moodledata/staticpage


3. If you want the users to login before they can see those static pages, modify this file:

/var/www/moodle/local/staticpage/view.php

as following:

...
// Require login if Moodle is configured to force login
//if ($CFG->forcelogin) {
//    require_login();
//}
require_login();
...


4. Clean URL for your static pages:

By default, the static page can be access via this URL:

http://yourdomain/local/staticpage/view.php?page=yourpagename

To make it pretty like this:

http://yourdomain/static/yhourpagename.html

add this rewrite rule to your nginx configuration:

...
        location /static {
                rewrite ^/static/(.*)\.html$ /local/staticpage/view.php?page=$1;
        }
...

Restart nginx:

$ sudo service nginx restart