Full v Relative web addresses

Full v Relative web addresses

by Anthony Cole -
Number of replies: 9

Why does Moodle use full web addresses to get to each page?

For example, when you already on www.moodle.org, why do you not use relative urls for (say) images(look through webpage source)? I configured moodle on a linux test machine (with wwwroot as http://krati/moodle where krait is the machine name, not in local DNS), and remote machines cannot see the images. Changing wwwroot to the ip address solved the problem, but it seems to me you don't need the full url anyway, so my question is why is it done this way?

A

Average of ratings: -
In reply to Anthony Cole

Re: Full v Relative web addresses

by Martin Dougiamas -
Picture of Core developers Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers
Because texts in Moodle can end up in different contexts.

For example, email-posted versions need full links. Also consider that a relative image in the editor is relative to the EDITOR script, not the final location.

Allowing a mix of relative/absolute also turned out to be very difficult when it comes to backup/restore issues and so on, so we standardised on the full URL everywhere so that at least scripts always know what's being referred to.
In reply to Martin Dougiamas

Re: Full v Relative web addresses

by piersante sestini -
There is a post on the Italian forum saying that a few modules (namely Lesson, SCORM, wiki and glossary) take the address directly from the machine and not by WEBROOT
This creates a problem because the poster has a server in an internal subnet connected to the Internet through a firewall, and those modules create links such as "http;//192.168.etc.." which cannot be resolved by the outside.
WEBROOT is set to the address of the firewall.
According to the report (I haven't tried miself), the other modules
behave correctly.

Is this a known issue?

thanks,
Piersante
In reply to piersante sestini

Re: Full v Relative web addresses

by Martin Dougiamas -
Picture of Core developers Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers
New to me ... someone should file bugs in the bug tracker for each module, with as much information to help locate the problem code as possible ...
In reply to Martin Dougiamas

Re: Full v Relative web addresses

by Randall Kindley -
Martin,

But is there a fix for this? I also need to make the addresses relative or at least able to pick up the server name from the server on which moodle resides.

I looked in /lib/editor/popups/insert_image.php to see what I might be able to change. Any ideas? Seems one could make the server part of the image's address a variable:

$_SERVER['SERVER_NAME'].$address_for_ntmoodle_image

Please advise.

Randall Kindley
In reply to Randall Kindley

Re: Full v Relative web addresses

by Martin Dougiamas -
Picture of Core developers Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers
Step back a moment ... why do you really need this?

If you are running the same site under multiple addresses then the best place to tinker with the $CFG->wwwroot is using PHP code in the main config.php (only).
In reply to Martin Dougiamas

Re: Full v Relative web addresses

by Randall Kindley -
Several reasons, here are a few:

I have created a CD version of my moodle, so that folks offline can do the courses. The CD loads an apache, mysql, and php server to their machine with the moodle in the htdocs. Everything works except that the absolute references point to the server used when creating the courses.

The same issue arises when you want to transfer a moodle from one server to the other (by just copying the moodle files and dumping the sql). Again, all absolute references are incorrect on courses created on the other server, since they are saved as those absolute, not relative addresses.

You might respond just use the backup/restore facility. That will not work for the first example (I would not expect my users to be expert admins), and is cumbersome for the latter.

Changing wwwroot doesn't help once you have saved any image reference (as in the editor).

In reply to Randall Kindley

Re: Full v Relative web addresses

by Lena Persson -

Hi Randall, & everyone

We hit the same problem just now.  We moved our moodle site from one server to another, but the images which were on the original site didn't display on the new one.   Investigation showed that they were being referenced as eg http://www.oldsite.com/moodle/file.php/1/picture.gif instead of their new location on www.newsite.com

Is there a way to do a global "find & replace" for all these references, do you know?   

In reply to Martin Dougiamas

Re: Full v Relative web addresses

by Randall Kindley -
//This is what I place in mod/lesson/view.php just above the print_simple_box(format_text($     ...usually $page->contents

//$new_text is whatever you have done to $page->contents

$content_array=explode("http", $new_text);
for ($i = 1; $i <= count($content_array)-1;  $i++)
{
//most people install into a directory called "moodle", so ...

    $moodle_pos=strpos($content_array[$i],"moodle/")+7;
    $rest = "../../".substr($content_array[$i],$moodle_pos);
    $content_array[$i]=$rest;
}
$new_text=implode("",$content_array);
In reply to Anthony Cole

Re: Full v Relative web addresses

by Brian Lockwood -

If you set up an A record in your dns server for the moodle server then internal machines can just use http://moodleserver whilst external machines will use the FQDN.

(Or have I misunderstood your problem mixed)

Brian L