Though it might look like an odd request, but I have a little problem. This machine I'm using to host moodle has 2 network cards, enabling it to be accessed from a LAN IP, like 192.168.0.1. Also, it has a public IP. But accessing the site through the public IP is slow, but it needs to be available online.
For this reason, I have to give the public IP for $CFG->wwwroot variable. But, this makes the site slow from the LAN IP too, because moodle retrives a lot of stuff from the $CFG->wwwroot variable. Which in effect is fetching stuff from the internet while the server is available locally. Is there any way I can avoid this? My problem will be solved if moodle takes whatever IP address is given in the browser as $CFG->wwwroot. Any thoughts?
TIA,
Vamsee.
In reply to Vamsee Kanakala
Re: Is there anyway to avoid $CFG->wwwroot to be hardcoded?
by John Papaioannou -
This isn't easy to do "automatically"... what you are saying is that you want Moodle to use a different $CFG->wwwroot depending on where the request is coming from (inside or outside the LAN).
But for your case, here is a very simple solution that should work most of the time and shouldn't give you problems. However, proceed with caution as always.
In config.php:
Cheers!

But for your case, here is a very simple solution that should work most of the time and shouldn't give you problems. However, proceed with caution as always.
In config.php:
$CFG->wwwroot = 'http://10.11.12.13'; // You already have this, it's your public IP
// Now add the following lines IMMEDIATELY AFTERWARDS:
$LAN_PREFIX = '192.168.0.';
if(substr($_SERVER['REMOTE_ADDR'], 0, strlen($LAN_PREFIX)) == $LAN_PREFIX) {
$CFG->wwwroot = 'http://192.168.0.1'; // Your LAN IP
}
// That's all!
Cheers!

In reply to John Papaioannou
Re: Is there anyway to avoid $CFG->wwwroot to be hardcoded?
by Vamsee Kanakala -
Thanks a lot Jon, it works! You saved me a lot of effort and my boss will be very pleased!
Regards,
Vamsee.
Regards,
Vamsee.