Moodle 5.0 / New Router Front Controller / 404 on Several Pages

Moodle 5.0 / New Router Front Controller / 404 on Several Pages

by Raymond Frangie -
Number of replies: 2

Hi All,

I upgraded our 4.5 site to the new 5.0, and everything runs smoothly. However, this new front controller / Moodle router feature will be compulsory from 5.1 onwards, so I figured I would deploy it now (given that it was there in 4.5 but not deployed for me anyway).

Whatever I do does not work smoothly. It appears to fail on several pages, yet several others work. The test page that always fails is the home page when clicking the home icon. It just throws a 404 error. If I try to click on My Dashboard, it does the same 404 error, but it says /my/ instead of the /?redirect=0 in the image below.

image.png

Disabling or reverting the changes, and it works perfectly fine. I am using the latest version of Apache on Ubuntu 22.04.5 and have followed the Moodle documentation here - https://docs.moodle.org/500/en/Configuring_the_Router

I have placed the FallbackResource directive into the Apache Site Configuration File.

image%20%281%29.png

Thinking it was our current mod_rewrite rules to hide Moodle's Internal Paths for security, disabling these rules/engine did not resolve the issue. They are as follows. These allow the Security Checks inside Moodle to report back successfully for unexposed internal paths.

image%20%282%29.png

Per the documentation, I have added the "routerconfigured" directive and set it to true in config.php.

image%20%283%29.png

The errors in the Apache error log file for the specific site show the 404 error as follows:

[Wed Apr 16 21:57:43.375310 2025] [php:notice] [pid 62903:tid 62903] [client 103.76.165.206:0] 404 Not Found
Type: Slim\\Exception\\HttpNotFoundException
Code: 404
Message: Not found.
File: /opt/sites/lms.tcsc.academy/lib/slim/slim/Slim/Middleware/RoutingMiddleware.php
Line: 76
Trace: #0 /opt/sites/lms.tcsc.academy/lib/slim/slim/Slim/Middleware/RoutingMiddleware.php(44): Slim\\Middleware\\RoutingMiddleware->performRouting()
#1 /opt/sites/lms.tcsc.academy/lib/slim/slim/Slim/MiddlewareDispatcher.php(121): Slim\\Middleware\\RoutingMiddleware->process()
#2 /opt/sites/lms.tcsc.academy/lib/classes/router/middleware/uri_normalisation_middleware.php(59): Psr\\Http\\Server\\RequestHandlerInterface@anonymous->handle()
#3 /opt/sites/lms.tcsc.academy/lib/slim/slim/Slim/MiddlewareDispatcher.php(121): core\\router\\middleware\\uri_normalisation_middleware->process()
#4 /opt/sites/lms.tcsc.academy/lib/slim/slim/Slim/Middleware/ErrorMiddleware.php(76): Psr\\Http\\Server\\RequestHandlerInterface@anonymous->handle()
#5 /opt/sites/lms.tcsc.academy/lib/slim/slim/Slim/MiddlewareDispatcher.php(121): Slim\\Middleware\\ErrorMiddleware->process()
#6 /opt/sites/lms.tcsc.academy/lib/slim/slim/Slim/MiddlewareDispatcher.php(65): Psr\\Http\\Server\\RequestHandlerInterface@anonymous->handle()
#7 /opt/sites/lms.tcsc.academy/lib/slim/slim/Slim/App.php(199): Slim\\MiddlewareDispatcher->handle()
#8 /opt/sites/lms.tcsc.academy/lib/slim/slim/Slim/App.php(183): Slim\\App->handle()
#9 /opt/sites/lms.tcsc.academy/lib/classes/router.php(310): Slim\\App->run()
#10 /opt/sites/lms.tcsc.academy/r.php(55): core\\router->serve()
#11 {main}, referer: https://lms.tcsc.academy/admin/search.php

I've checked to ensure those files (r.php, RoutingMiddleware.php, etc.) all exist, and they all do, so it's not them, as far as I can tell. Line 76 of that file is just where it throws the exception.

I don't have any guidance on having to install a specific PHP component or other package for Slim, so no action taken there.

I'm stumped, so I'm contacting you all to see if anyone has managed to get this working. For now, the router is disabled and the site works, but given its compulsory nature coming in the next 5.1, I'd like to ensure it's all working now.

Appreciate the assistance!

Cheers,
Ray.

Average of ratings: -
In reply to Raymond Frangie

Moodle 5.0 / New Router Front Controller / 404 on Several Pages

by Bob Gilmore -
Picture of Particularly helpful Moodlers
I had a bunch of problems with it in testing, generating 404s, until i specified the directory index:
<VirtualHost _default_:443>
   ServerName test.trainingforlife.nz
   DocumentRoot /var/www/test.trainingforlife.nz/moodle
   <Directory /var/www/test.trainingforlife.nz/moodle>
        AllowOverride none
        Require all granted
        DirectoryIndex index.php
        FallbackResource /r.php
   </Directory>
</VirtualHost>

Average of ratings: Useful (1)
In reply to Bob Gilmore

Moodle 5.0 / New Router Front Controller / 404 on Several Pages

by Raymond Frangie -
Hi Bob,

Yes! This did the trick. Adding the DirectoryIndex index.php fixed the issue with all the areas where I got the 404s, primarily the home and dashboard. The Apache error log does not spill out the errors as before.

I don't know if it's me, but it also appears that adding that directive makes the pages load much quicker.

I have just made the change on the official documentation as well and submitted for approval smile 

Greatly appreciate the assist, Bob.

Cheers,
Ray.