Configuring the Moodle router for clean URLs starts with knowing what it changes
Moodle 5.1 added a routing engine for cleaner URLs, which is recommended but optional, and it includes a compatibility layer for older setups. For a team running or planning a self-hosted Moodle, the decision is not whether the feature exists but whether your URLs, reverse proxy and custom code need to change to use it. The routing engine changes how Moodle maps incoming paths to its scripts, so anything that hard-codes script paths, such as a proxy rule, a bookmark standard, an SSO return address or a link in an integration, deserves a review before you switch it on. The Moodle 5.1 release notes are the reference for what the engine covers and how the compatibility layer behaves.
You should plan for the routing engine now if you are doing a new install on Moodle 5.1 or later, if your organization has custom plugins or local code that build URLs by hand, or if a reverse proxy, load balancer or API gateway sits in front of Moodle and rewrites paths. In those cases the web server rewrite rules, the routerconfigured setting and the fallback to r.php all need to agree, and the 5.2 environment check is the place Moodle reports a mismatch. You can defer the change if you are running an existing site with stable integrations that you have not yet tested against the new paths and you are not on a release that requires it. Confirm with your own environment which of your integrations build URLs, because that inventory sets the testing effort more than the Moodle setting does.
Router configuration options and when each fits
This table compares the three ways to run Moodle 5.1 and later: the routing engine with web server rewrite rules, the compatibility layer with r.php URLs, and routing without a rewrite. Read each row against your server control and the links your users, plugins and integrations already depend on. Confirm the default value of routerconfigured in your release before you change anything.
| Option | Web server work | Effect on existing links and plugins | Main risk |
|---|---|---|---|
| Routing engine with rewrite rules | Change the web server configuration to send requests through the front controller, and point the document root at /public | Clean URLs for new links; plugins and integrations that build URLs through Moodle's APIs continue to work after a test pass | A missed rewrite rule causes errors or broken pages, so test every route family before go-live |
| Compatibility layer with r.php URLs | No rewrite rules needed beyond the standard /public document root setup | Existing bookmarks, LTI tools and hard-coded r.php links keep working without change | Longer URLs remain, and any new clean-URL work will need to be revisited later |
| Routing without a web server rewrite | Keep the current server configuration; Moodle handles routing through its own fallback path | Clean URLs where the server cannot be changed, but behavior depends on the fallback being reached for every request | Edge cases such as static assets or direct file paths may behave differently, so verify them on your stack |
| Plugin URLs built with core helpers | Little or no server change, since the plugin relies on Moodle's URL functions | Usually adapts to either mode, but hard-coded paths in older code do not | Plugins that concatenate paths by hand will break when the routing mode changes |
| Links in external systems | None on Moodle; may need updates in the portal, LMS links or LTI tool configuration | Deep links stored outside Moodle may point to the old form and need a redirect or update plan | Silent broken links in other systems that nobody owns |
| Reverting after go-live | Rewrite rules and document root can be rolled back with the web server configuration | Routes served under the new scheme stop resolving when the mode is switched back | Users who bookmarked clean URLs lose access unless redirects are kept in place |
Setting up clean URLs on Moodle 5.1 and later
This sequence moves a Moodle site onto the routing engine in a fixed order, so the web server, configuration and URL generation change together. Each step closes with a check, so a failure is found before the next change is made.
Confirm release, PHP and database versions
The platform owner confirms the target Moodle release and checks the server against that release's requirements. For Moodle 5.1, the minimum is 64-bit PHP 8.2 or later, and the database must be PostgreSQL 15, MySQL 8.4, MariaDB 10.11 or SQL Server 2017 or later. Sites must already be on Moodle 4.2.3 or later to upgrade. Confirm the 5.2 requirements in the release notes before planning that version. The step is done when
php -vand the database server version both match the release requirements and the site's current version is recorded.Point the document root to public
The web server administrator changes the document root from the main Moodle folder to the
publicdirectory that ships from Moodle 5.1. Without this change, the site may show directory listings or errors. Only the document root changes in this step. The configuration file, the data directory and the code stay where they are. The step is done when the site's home page loads through the new root and a request for a path outsidepublic, such as the configuration file, is refused.Add rewrite rules for your web server
The web server team adds the rewrite rules that send requests for clean paths to Moodle's routing layer. The rules differ between Nginx, Apache and other servers, so the team should take the current rules from Moodle's documentation for the release in use and apply them to the site's server block or virtual host. The
r.phpfallback must stay in place so that requests the rules do not match still reach Moodle. The step is done when the server's configuration test passes and a nested course or activity path returns a page instead of a 404 error.Set routerconfigured in configuration or admin
The Moodle administrator turns on the router by setting
routerconfiguredinconfig.php, or in the site administration settings where the release provides them. The setting should be changed only after the rewrite rules pass, because Moodle will then generate clean links that the web server must answer. Record which method was used so that future upgrades keep the setting. The step is done when the setting is saved, the value reads back as enabled, and a page the administrator opens shows clean links.Purge caches and reload the site
The Moodle administrator purges all caches from the site administration area, then reloads the site from a fresh browser session. Cached pages and navigation blocks can keep old URLs after the router is enabled, so this step removes them before testing. The cron task should also run once so that any scheduled link generation uses the new settings. The step is done when the main navigation, a course page and an activity link all show the new URL form and none of them return an error.
Run the environment check on 5.2
On Moodle 5.2, the administrator opens the environment check in site administration and reviews any item that relates to routing or the web server configuration. The check reports whether the server meets the requirements for the router, so each failure needs a fix in the web server or PHP setup, not a workaround in Moodle. Confirm the exact checks and their wording in the 5.2 release notes. The step is done when the environment check shows no routing-related errors and the results are saved with the change record.
Test pages, logins, downloads and web services
The test lead works through a fixed set of checks on a staging copy before production. The set covers course and activity pages, each enabled sign-in method, a file download from a course, a file upload, and at least one web service call from an external client. Plugins that build URLs by hand, such as custom themes or local plugins, should be tested separately because they may not use the router. The step is done when every check passes, each failure has a logged cause, and the results are signed off by the platform owner.
How a request flows through the web server, router and r.php fallback
The flow starts when a browser requests a clean URL, such as a course or activity path, at the web server that serves the Moodle /public document root. The web server's rewrite rules decide whether the request goes to the Moodle application as a clean path or passes through unchanged. Moodle's routing engine then tries to match the path to a registered route. When no clean route matches, the request falls back to r.php and is handled the way older Moodle URLs always were. Check that rewrites reach the application and that old links still resolve.
Request path from browser through web server, router and r.php fallback.
Router setup differs by web server and hosting model
On an Apache server, the routing engine depends on rewrite handling being enabled for the Moodle virtual host and on requests for non-file paths being passed to Moodle's entry point. Moodle 5.1 introduced the routing engine as recommended but optional, and it keeps a compatibility layer for older setups, so you can enable the new behavior in a controlled step rather than in the same change as the upgrade itself. The main work is confirming the virtual host points at the /public directory and that the rewrite rules Moodle expects are present and not overridden by a parent .htaccess or a server-level default.
- Document root: From Moodle 5.1, the web server document root must point to
/public, or the site may show directory listings or errors. - Rewrite module and overrides: Confirm the rewrite module is loaded and that
AllowOverridepermits the rules Moodle ships, so per-directory rules are not silently ignored. - Router setting: Enable the
routerconfiguredsetting only after the rewrite path works, and record the change in your configuration management. - Fallback behavior: Test that requests for paths without a matching file reach the
r.phpfallback as the release notes describe. - Plugin URLs: Check any plugin that builds links by hand, because those links can break when clean URLs are enabled.
Before you enable the setting, confirm the exact rule set against the Moodle 5.1 release notes and the installation documentation for your release.
Nginx does not read per-directory rewrite files, so the routing behavior lives in the server block that serves Moodle. Requests for paths that do not map to a real file must be handed to Moodle's entry point through a fallback rule, typically written with try_files. The same document root change applies here, and the PHP-FPM handler must receive only the requests that Moodle should process. Because these rules sit in the server configuration, every change needs a reload and a review by whoever owns the Nginx build.
- Document root: Point the
rootdirective at/publicfor Moodle 5.1 and later, and keepmoodledataoutside it. - Fallback rule: Use the fallback the release notes and installation guide describe for the routing engine, and confirm the exact pattern in the Moodle documentation for your version.
- PHP handling: Make sure only PHP entry points reach PHP-FPM and that static files are served directly, so the fallback does not hide missing assets.
- Reload and test: Validate the configuration syntax and reload the service in a staging environment before production.
- Direct access checks: Request a few routes with and without a trailing slash and confirm the response, the redirects and the PHP error log.
The release notes and Moodle's installation documentation are the authority for the exact fallback syntax, so confirm it there before you copy anything into production.
When a reverse proxy, load balancer or ingress controller sits in front of Moodle, the routing engine must work across two layers: the edge component that receives public requests and the web server that runs Moodle. The edge layer may rewrite paths, terminate TLS and forward headers, and any mismatch between what the client requests and what Moodle sees can produce redirect loops, wrong host names or broken links. Decide which layer owns clean URL handling, and document it so the team does not configure the same rewrite twice.
- Ownership decision: Choose whether the edge or the Moodle web server performs the fallback, and keep the other layer a plain forwarder.
- Forwarded headers: Confirm the scheme, host and client address headers reach Moodle and that the Moodle site URL matches the public address.
- Path handling: Check that the proxy does not strip or rewrite the path in a way the routing engine does not expect.
- Multiple nodes: If several web nodes sit behind the balancer, apply the same routing configuration to every node and test each one.
- Health and redirects: Verify health checks reach a valid Moodle page and that redirects do not loop.
Test through the public address, not only the internal one, because proxy behavior is where most routing faults appear. Confirm header and proxy settings against the Moodle documentation for your release and your edge product.
Whatever the server or proxy, the verification steps are the same in principle: prove that generated URLs, direct requests and plugin links all resolve after the change. Moodle 5.1 added the 5.2 environment check path for confirming a valid setup, so use the environment check report as one input, not the only one. Run the checks in staging with a copy of production data and record the results, because routing faults often appear only in pages that build URLs in unusual ways.
- Environment check: Review the environment report after enabling the setting and resolve any warnings it lists.
- Generated links: Open course pages, activity links, file downloads, login and logout, and the admin pages and confirm each resolves.
- Direct requests: Request non-existent paths and confirm the fallback response matches the expected behavior.
- Plugin inventory: List installed plugins that build URLs and test each one, especially third-party plugins.
- Rollback plan: Keep a documented way to disable the setting and restore the previous rules quickly.
Ask your implementation partner or internal team to write the test cases before the change, so that the sign-off is based on a defined list rather than a spot check.
Security and operational risks when changing URL routing
Changing how Moodle builds and serves URLs touches the document root, the web server, login flows and every plugin that stores or generates links. The six risks below share one root cause: a URL that works in one layer can break or expose something in another, so each card names the check that confirms the change is safe before users see it.
Exposing the wrong directory
From Moodle 5.1 the web server document root must point to the new /public directory rather than the main Moodle folder. If the root still points at the top-level folder after the change, the site may show directory listings or errors, and code and configuration files that should sit outside the browser's reach can become visible. Confirm the root path in the server configuration, then request a few known internal paths and check that each returns a not-found response.
Broken file serving and downloads
Rewrite rules that send requests to r.php or other front controllers can intercept requests for course files, theme assets and downloads. A rule that is too broad can return HTML instead of a file, and a rule that is too narrow can cause missing images and failed downloads. Test a representative set of file types, large files, and resources from a theme and an activity after each rule change, and watch the web server error log during the test.
Login and SSO redirect failures
Identity provider configurations store the callback and return URLs that Moodle expects. If the site's base address or the path to the login endpoint changes, sign-in can fail with redirect mismatch errors, or users can land on an address that the identity provider rejects. Before changing routing on a site that uses SAML 2.0 or OAuth 2, list every registered callback URL with each identity provider owner, update them in the same change window, and run a full sign-in and sign-out test with a test account.
Stale URLs in plugins and integrations
Plugins, blocks, LTI tool registrations, web service clients and external systems can hold absolute links that were generated before the change. Those links may still resolve through a compatibility layer today but fail after it is removed or after a plugin update. Inventory the systems that receive Moodle links, such as video tools, document services and reporting pipelines, and ask each owner to confirm the new URL format and to schedule a retest after the change.
Reverse proxy header mismatches
When Moodle sits behind a load balancer or reverse proxy, the scheme, host and port that Moodle reads from forwarded headers determine the URLs it generates. A mismatch can produce http links on an https site, redirect loops, or links to an internal host name. Check that the proxy sends the forwarded headers Moodle is configured to trust, and that the configured site address matches the public address. Verify the generated links on a logged-in page and in an outgoing email.
Change control for config.php settings
Routing behavior is set through configuration that can be changed outside the database, so a manual edit on one server can make the environments diverge. Record the routing setting, the site base address and any proxy-related values in version control, review each change, and keep the previous file so a rollback is a single step. Confirm the change on staging with the same web server configuration as production before it is promoted, and record who approved it.
Questions teams ask before changing Moodle URL routing
Do we have to turn on clean URLs in Moodle?
No. The routing engine added in Moodle 5.1 is recommended but optional, and a compatibility layer keeps older setups working. The practical question is whether your current URL structure causes problems for your integrations, bookmarks or plugins that build links. If nothing in your environment depends on the old paths, you can leave routing alone for now. If you plan a move to a newer release, check the Moodle 5.1 release notes first, because the web server changes that come with the router are the part most likely to need planning. Ask your team to inventory every system that links into Moodle before deciding.
How much effort does a Moodle router change take, and what drives it?
The effort depends mostly on four things: how much control your team has over the web server configuration, how many plugins build or parse URLs, how many external systems link into Moodle, and how wide the testing scope must be. Each one adds work. A single-server setup where you edit the Nginx or Apache configuration directly is simpler than a load-balanced or managed platform where a separate team owns the edge. Ask any partner for a quote that lists each of these four drivers separately, the test cases it covers and who performs the retest. Do not accept a single number without that breakdown.
What does the internal team need to provide for the change?
Expect to provide access and decisions, not just time. The team needs someone who can change the web server configuration and reload it in a non-production environment, someone who owns the Moodle config.php file, and a person who knows the integrations and custom plugins well enough to say which URLs they depend on. You also need a staging copy of the site with realistic data and a maintenance window agreed for production. Confirm these roles early, because a delay in any one of them usually delays the whole change.
Can our own team make the router change without outside help?
Yes, if your team already runs Moodle on your web server and can test the result thoroughly. The change itself is a configuration update plus the routing setting and a check of the environment page, so the work is manageable for an experienced administrator. The harder part is the testing: confirming that every plugin, theme, link and integration still resolves correctly. If your team lacks the time or the test coverage, an implementation partner can take that work under a written scope. Ask whether the partner will test in your staging environment and document the result for your own records.
What breaks if we roll back a router change?
Rolling back depends on which parts you changed. If you only reverted the routing setting, Moodle should continue to serve pages through the compatibility layer, but any links, bookmarks or plugin URLs generated while routing was active may need checking. If you changed the web server document root to the /public directory and then reverted it, the site can show directory listings or errors until the web server points back correctly. Before any change, record the previous web server configuration, the setting value and a database and file backup so you can restore the exact prior state. Test the rollback in staging as well, not only the change.
What does a DeployOpen engagement cover for Moodle routing?
A DeployOpen engagement is fixed-scope, so the scope, deliverables and timeline are agreed in writing before work starts. For routing, that scope can include reviewing your current web server and Moodle configuration, planning the rewrite rules and the routerconfigured setting change, applying the change in your environment, checking the environment page, testing the URLs that matter to your plugins and integrations, and documenting the rollback steps. DeployOpen works inside your infrastructure. It does not issue compliance attestations for your routing setup. Ask for a written quote that names each deliverable and the test cases it covers.
How DeployOpen scopes and delivers Moodle routing changes
DeployOpen treats the Moodle router as a configuration change to a live site, not a one-line setting. We scope the web server rewrite rules, the routerconfigured setting and the r.php fallback against your current URLs and plugins, then build and test the change in your own infrastructure. Every step is written down so your team can repeat it on each upgrade.
How we scope
- We inventory your Moodle version, web server, document root and any URLs that bookmarks, integrations or plugins depend on.
- We list the custom and third-party plugins that build URLs, so their routing behavior is tested before the change.
- The written scope states which environments, sites and checks are covered, and it is agreed before work starts.
How we build
- We configure the web server rewrite rules and the routerconfigured setting in a staging copy that matches production.
- We confirm the r.php fallback handles requests the rewrite rules do not match, and we check the environment check results.
- We test key pages, course links, file downloads and plugin-generated URLs, then record each result for your review.
How we hand over
- You receive the rewrite configuration, the settings changed, and a step-by-step runbook for applying them again.
- The documentation records which plugin URLs were tested and which need a follow-up check after upgrades.
- We walk your administrators through the verification checks so they can confirm routing after future releases.
How we support
- Ongoing support, upgrades and continuous testing are available as a retainer, which can cover routing checks at each Moodle release.
- Before each point or major upgrade, we can retest the routing configuration and the plugins that generate URLs.
- Support requests are handled against the written scope, so changes to routing rules follow the same review and record process.

