Setting up Moodle on NGINX with Pretty URLs
How to Add Pretty URLs for Moodle Pages
Tutorial: Setting Up Pretty URLs for Moodle on NGINX
This guide explains how to configure NGINX so that your Moodle pages are accessible through clean, readable URLs such as:
https://SAMPLEDOMAIN.com/about
https://SAMPLEDOMAIN.com/contact
https://SAMPLEDOMAIN.com/licensesinstead of the default Moodle structure:
https://SAMPLEDOMAIN.com/local/page/?id=3
https://SAMPLEDOMAIN.com/local/page/?id=4
https://SAMPLEDOMAIN.com/local/page/?id=21. Open Your NGINX Configuration
Edit your NGINX server block for your site (usually located in /etc/nginx/sites-available/SAMPLEDOMAIN.com):
2. Add Rewrites for Pretty URLs
Inside your main server { ... } block, locate or create a section for your Moodle site.
Add the following block:
✅ What this does
Each line tells NGINX to:
Match a friendly URL (e.g.,
/about)Redirect internally to the correct Moodle page (e.g.,
/local/page/?id=3)Keep the clean URL visible in the browser
3. How to Add a New Pretty URL
Let’s say you created a new Moodle page with ID 6 and want it to be available at
https://SAMPLEDOMAIN.com/support.
Just add this line inside the same block:
Now /support will display Moodle’s page ID 6.
4. How to Rename or Change a URL
If you want to rename /faq to /help, just replace:
with:
5. Full Example Configuration
Here’s a complete working example, ready to use:
✅ Result:
Any slug at the root level (
/licenses,/about, etc.) automatically maps to your PHP page controller.No hardcoding of
id=Xrequired.Works with an unlimited number of pages.
Last updated