Configuring the Moodle router for clean URLs

Moodle 5.1 added an optional routing engine for cleaner URLs. This page explains what it changes, how to set the web server rewrite rules and routerconfigured setting, and what to test before you enable it.

On this page

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.

OptionWeb server workEffect on existing links and pluginsMain risk
Routing engine with rewrite rulesChange the web server configuration to send requests through the front controller, and point the document root at /publicClean URLs for new links; plugins and integrations that build URLs through Moodle's APIs continue to work after a test passA missed rewrite rule causes errors or broken pages, so test every route family before go-live
Compatibility layer with r.php URLsNo rewrite rules needed beyond the standard /public document root setupExisting bookmarks, LTI tools and hard-coded r.php links keep working without changeLonger URLs remain, and any new clean-URL work will need to be revisited later
Routing without a web server rewriteKeep the current server configuration; Moodle handles routing through its own fallback pathClean URLs where the server cannot be changed, but behavior depends on the fallback being reached for every requestEdge cases such as static assets or direct file paths may behave differently, so verify them on your stack
Plugin URLs built with core helpersLittle or no server change, since the plugin relies on Moodle's URL functionsUsually adapts to either mode, but hard-coded paths in older code do notPlugins that concatenate paths by hand will break when the routing mode changes
Links in external systemsNone on Moodle; may need updates in the portal, LMS links or LTI tool configurationDeep links stored outside Moodle may point to the old form and need a redirect or update planSilent broken links in other systems that nobody owns
Reverting after go-liveRewrite rules and document root can be rolled back with the web server configurationRoutes served under the new scheme stop resolving when the mode is switched backUsers 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.

  1. 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 -v and the database server version both match the release requirements and the site's current version is recorded.

  2. Point the document root to public

    The web server administrator changes the document root from the main Moodle folder to the public directory 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 outside public, such as the configuration file, is refused.

  3. 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.php fallback 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.

  4. Set routerconfigured in configuration or admin

    The Moodle administrator turns on the router by setting routerconfigured in config.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.

  5. 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.

  6. 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.

  7. 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 AllowOverride permits the rules Moodle ships, so per-directory rules are not silently ignored.
  • Router setting: Enable the routerconfigured setting 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.php fallback 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.

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.

Moodle 5.1 release notes

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.

Sources and further reading

Talk to our team.

Tell us what you're working on, whether it's a deployment, an audit, a security test or a cyber range. You'll speak with an engineer who can help you scope it.

  • 30-minute call: free, with no obligation.
  • NDA on request: we can sign before you share details.
  • Clear next steps: a scope and plan after the call.