Broke file links

Broke file links

by Jason De Donno -
Number of replies: 8

When trying to access certain files (that are resources on courses), we are getting the error:

Incorrect access detected, this server may be accessed only through "http://www.test.aspero.nu/moodle" address, sorry. Please notify server administrator.

When I click on the file's link, the address that comes up isn't the same - it is missing the www. So the links are broken.

It appears to be remembering the old address of the moodle site, that did not have the www.

How can we fix this?

 

Average of ratings: -
In reply to Jason De Donno

Re: Broke file links

by Mark Johnson -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

It sounds like you need to modify $CFG->wwwroot in config.php. If you try and access Moodle through an address other than that one, you get the error you described.  It also uses this value when outputting programattically generated URLs, but if you created a link in the WYSIWYG editor you'll need to recreate the links after changing wwwroot.

In reply to Mark Johnson

Re: Broke file links

by Jason De Donno -

Thanks Mark. The $CFG wwwroot has been changed, and this is what has caused the problem. The files that are affected are earlier files that  uploaded by a teacher using the WYSIWYG editor before we changed the $CFG wwwroot. 

So how can I repair the links?

In reply to Jason De Donno

Re: Broke file links

by Mark Johnson -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

While other links such as those to courses or resources are generated programatically when the page is viewed, links created in the WYSIWYG editor are stored as static HTML at the time the are created.  To change them you'll need to open up the text containing the link in the editor, highlight it, click the "Create/Edit Link", and re-create the link to the file - it should then pick up the new wwwroot.

In reply to Mark Johnson

Re: Broke file links

by Jason De Donno -

The problem is the links to the documents themselves in Moodle. For example, if I want to open a word doucment resource, I click on the word doucment icon or link, that is when the error occurs. It's with the older files its happening.

In reply to Jason De Donno

Re: Broke file links

by Davo Smith -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

You might want to try out the script at

(Moodle 1.9) http://[yourmoodlesite]/admin/replace.php

(Moodle 2.x) http://[yourmoodlesite]/admin/tool/replace

That should allow you to replace every occurrance of the old URL in your site, with the new one (warning - be careful, you could do a lot of damage to your site with this tool if you do the wrong search & replace).

Davo

In reply to Davo Smith

Re: Broke file links

by Jason De Donno -

Thanks! So this can be used to replace part of URL? It's no good if it replaces the whole of the url beacuse obviously each one is unique.

In reply to Jason De Donno

Re: Broke file links

by Davo Smith -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

It can be used to replace any part of string you like, if you choose to replace 'http://www.myboringoldmoodlesite.com/' with 'http://www.mysupernewmoodlesite.com/' then only that part of the string will be replaced: e.g.

'http://www.myboringoldmoodlesite.com/course/view.php?id=5' will become 'http://www.mysupernewmoodlesite.com/course/view.php?id=5', etc.