Full v Relative web addresses

Full v Relative web addresses

- Anthony Cole の投稿
返信数: 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

Anthony Cole への返信

Re: Full v Relative web addresses

- Martin Dougiamas の投稿
画像 Core developers 画像 Documentation writers 画像 Moodle HQ 画像 Particularly helpful Moodlers 画像 Plugin developers 画像 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.
Martin Dougiamas への返信

Re: Full v Relative web addresses

- 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
Martin Dougiamas への返信

Re: Full v Relative web addresses

- 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
Randall Kindley への返信

Re: Full v Relative web addresses

- Martin Dougiamas の投稿
画像 Core developers 画像 Documentation writers 画像 Moodle HQ 画像 Particularly helpful Moodlers 画像 Plugin developers 画像 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).
Martin Dougiamas への返信

Re: Full v Relative web addresses

- 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).

Randall Kindley への返信

Re: Full v Relative web addresses

- 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?   

Martin Dougiamas への返信

Re: Full v Relative web addresses

- 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);