I am unsure how moodle determines what url you have typed. You can try the following (but I can't test if it actually works):
Set your config to $CFG->wwwroot = 'http://moodle.mcst.edu.sa';
Put a .htaccess
file in your www-root and add the following to it:
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/moodle
RewriteRule ^(.*)$ /moodle/$1 [L]
This is a rule for mod_rewrite.
- It first checks if the url between the host and before the query string (
asdf
inexample.com/asdf?qwer=1
) can be matched by the regex^(.*)$
. It won't probably surprise you that this is true for any url. The entire url is stored as the first capture group (because of the brackets; it has preg-like syntax). - It then checks if all conditions are true.
%{REQUEST_URI}
is the part of the url we matched in step 1, but with a prefix slash. We check if it doesn't start with /moodle already. This way we prevent the rule from matching itself, which would result in an endless loop. - If step 2 is true, then we rewrite the url to
/moodle/$1
.$1
is replaced by the first capture group in step 1. The flag[L]
stops rewriting for this cycle, and the lack of the[R]
flag will make this an internal rewrite (instead of an external redirect). - The next cycle it will try to do all these steps again, but it will now fail on step 2. The internally rewritten url already starts with
/moodle
and therefore the condition is false.