Linking to images with 2 different $CFG->wwwroot's

Linking to images with 2 different $CFG->wwwroot's

ដោយ Adam Hayward នៅ
ចំនួនតប៖ 1
OK, here's another good one.

My site runs mostly on an internal company LAN, but a number of people access it from externally.

The PC's on the LAN access the site directly using the private IP of the webserver: 192.168.10.96, so for them the $CFG->wwwroot variable is set to http://192.168.10.96/

People accessing the site externally use the fixed, public IP of our firewall / router; the router uses NAT to forward the requests to the local webserver.

I do this with the following code in /config.php:

if ( strstr($_SERVER['REMOTE_ADDR']), "192.168." !== ($_SERVER['REMOTE_ADDR'] )
{
$CFG->wwwroot = 'http://<public_ip_of_router>/';
} else {
$CFG->wwwroot = 'http://192.168.10.96/';
}

Now the problem arises with images embedded within books etc have the entire URL kind of hardcoded into them. This means that images added by users on the LAN aren't visible to external users and vice versa. Does anybody know how I can get round this?

Thanks in advance,

Adam
មធ្យមភាគនៃរង្វាយតម្លៃ: -
ឆ្លើយតបទៅកាន់ Adam Hayward

Re: Linking to images with 2 different $CFG->wwwroot's

ដោយ Darren Spilling នៅ

I have also had this problem.

There is an easy fix:

Create a DNS entry for your LAN IP that matches your Domain name / public IP.

For example - internally mymoodlesite.com = internal (network IP)

externally mymoodlesite.com = public IP.

If all users use the domain name to access the site and the domain name is specified in the config.php there will be no problems with links.

Darren

មធ្យមភាគនៃរង្វាយតម្លៃ: -