Open nyanginator opened 6 years ago
Narrowed it down to classes/url_rewriter.php
. In the function html_head_setup_info()
, when a new moodle_url
is created with $ME
, the Moodle directory (in my case, "'/moodle") is prepended to the path automatically. Doing a check for the Moodle directory at the start of the string, and removing it if present, seems to fix the issues I mentioned above.
private static function html_head_setup_info() {
global $CFG, $ME, $PAGE;
// Remove Moodle directory at beginning of URL, if present
$wwwroot = new moodle_url($CFG->wwwroot);
$wwwpath = $wwwroot->get_path();
if (substr($ME, 0, strlen($wwwpath)) === $wwwpath) {
$ME = substr($ME, strlen($wwwpath));
}
// Continue with the rest of the code as usual ...
$me = new moodle_url($ME);
...
}
thanks @nyanginator
I'm on long term leave from Catalyst so can't really spend much time on this. If you can put together a pull request including unit tests for this then someone will probably merge it in for you.
Thanks for the reply. I haven't done unit tests before, so it may take me awhile to read up on it and set everything up. From my initial tries, it looks like the Moodle setup for PHPUnit doesn't play nice with XAMPP, or at least how XAMPP is on my system. I'll be working on reinstalling my LAMP stack using tasksel
(Ubuntu-based distro).
Do you or anybody else happen to have a link handy to a previous pull request with accompanying unit tests that I can use as a reference?
In theory this should be everything you need:
Thanks, I think I got it. Pull request https://github.com/brendanheywood/moodle-local_cleanurls/pull/129. Included additional test cases:
Hi, I wasn't sure where to post to reference the Development Branch, so sorry if I am posting in the wrong place.
EDIT: Added additional test case of /moodle/course/index.php
In the Master Branch, I could go to an unclean URL and have them resolve as follows:
http://192.168.1.10/moodle/course/My+Course+Shortname
http://192.168.1.10/moodle/course/
http://192.168.1.10/moodle/course/My+Course+Shortname/page
http://192.168.1.10/moodle/course/My+Course+Shortname/page
However, in the Development Branch, I get:
http://192.168.1.10/moodle/course/view.php?id=3 (page loads, but URL is still unclean)
http://192.168.1.10/moodle/moodle/course/ (page loads and index.php is gone, but URL is still unclean and has the Moodle directory appearing twice)
http://192.168.1.10/moodle/mod/page/?id=3 (page loads, but URL is still unclean)
http://192.168.1.10//moodle/moodle/mod/page/?id=3 (page loads, but URL is still unclean and has the Moodle directory appearing twice)
Actually, I didn't even know about the last 2 test cases until I looked at the cleaner code. Where does this link (to display all mods of a certain course) usually appear?
I know this is an experimental side project, so any help or insight is very much appreciated.
Thanks again!