Switched to HTTPS - images now broken

Switched to HTTPS - images now broken

by Alex Vanden Bosch -
Number of replies: 8

Hi all!

Recently we changed our site to HTTPS (security, hooray!) but in doing so, when we export a course to restore elsewhere the images do not show on that build (boo, broken!). Any ideas?

Thanks!

Average of ratings: -
In reply to Alex Vanden Bosch

Re: Switched to HTTPS - images now broken

by Ken Task -
Picture of Particularly helpful Moodlers

Run 'Search and Replace' tool

https://yoursite/admin/tool/replace/

search for http://yoursite/

replace with https://yoursite/

Uhhh ... make sure you have a backup of your DB first.  Now that makes it sound like it won't work ... not true .. have used it ... does work.   The backup covers the chance for human error.

'spirit of sharing', Ken


In reply to Ken Task

Re: Switched to HTTPS - images now broken

by Alex Vanden Bosch -

Hi Ken,

Apologies for the delayed reply, I wanted to test it first and for that I needed to check we had a back up, etc... Aaaanyway, that worked a treat! 

Thank you very much for the help!

In reply to Ken Task

Re: Switched to HTTPS - images now broken

by Alex Briones -

Ken,

I have done the search and replace on a site, but some of the images are still pointing to the old url. I say some because most other links are working as they should. Is the problem with these images' links because the links are hard coded?

Also, when doing the search and replace is it always better like this? 

old: http://sitename

new: https://sitename

Another way would be this, change the config,php to specify root-domain with https correct? 

Thanks

In reply to Alex Briones

Re: Switched to HTTPS - images now broken

by Ken Task -
Picture of Particularly helpful Moodlers

The config.php should have only one .... an https site should be using all https internal url's.

What version of Moodle?

In a 3.5 there are now 2 tools for making site http -> https conversions ...

admin/tool/replace/ ... the old one which used to work just fine.

and

admin/tool/httpsreplace/ ... obviously this one would be the one to use in your case .... *IF* your site is a 3.5.

The other way ... manual labor .... put site in maintenance mode.   Do an SQL dump.   Edit the SQL dump with an editor that has search and replace ... search for http://yoursite/ replace with https://yoursite/  Re-import DB to a new DB.  Change config.php to point to new DB.   Fingers X'd ... fixed.

Seems to me that somewhere along the way, HTML blocks used as internal navigation, etc. did use plain-ole html ... but something obscured ... security issues of some sort?, I guess.

Since those were encoded don't think the replace tool could find and change those.

'spirit of sharing', Ken



Average of ratings: Useful (1)
In reply to Ken Task

Re: Switched to HTTPS - images now broken

by Alex Briones -

Thanks Ken,

The version I have is Moodle 2.8  on linux and getting the site ready to migrate to 3.2.7 and so I have been testing the new site locally.

Basically, I ran the search and replace thus:

old: http://sitename 

new: http://sitename

then I changed the CFG-root = https

Now, I get a prompt to use https on all the pages, and some of the images are being redirected to the old site ( this is the problem).

However, if I explicitly request the url, the images in question ( a few of them ) redirect to the correct pages. Somehow, the pages are being redirected to the old site.


So, please correct me here, what i need to do is to run the search and replace tool again to convert all the internal urls from http --> https??

In reply to Alex Briones

Re: Switched to HTTPS - images now broken

by Ken Task -
Picture of Particularly helpful Moodlers

Am confused about this strand/thread ... probably because your posting is mixed in with another users.

So ... if you did what you said:

"Basically, I ran the search and replace thus:

old: http://sitename 

new: http://sitename"

You changed nothing ... when moving from http to https the search should have been for:

http://oldsite.fqdn/ (see the http://)

to

https://newsite.fqdn/

See the difference?

Two sites cannot have the same FQDN cause they map to different iP addresses.

So if you have some local copy of your production site and the search/replace works, you still might be able to pull resources from the production site into the local copy.

The way around that is to edit the local /etc/hosts file and make an entry:

privateIP fqdnofsite shortcutname

like:

192.168.0.12 www.mycoolmoodle.org mycool

All systems read host file first before making queries of DNS.

The other issue using localhost ... the cert ... don't think you can get a valid cert nor use the same cert from your Production server on a localhost implementation.   So the localhost web server / moodle is set to use https:// but the cert would not be valid ... so in firefox one has to make the exception.

Oh, yeah ... for https to work, port 443 must be open and, of course, one must edit the config.php file and change the  http:// to an https:// .... config.php file is read and re-read all the time.

'spirit of sharing', Ken


In reply to Alex Vanden Bosch

Re: Switched to HTTPS - images now broken

by Emma Richardson -
Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Plugin developers

Are you saying that you are exporting the course to a different moodle installation?  If you are on the same site, Ken is right on the replace tool but if it is on a different site that might be a different issue.

In reply to Emma Richardson

Re: Switched to HTTPS - images now broken

by Alex Vanden Bosch -
Hi Emma,

Thanks for the response! As mentioned above, Ken nailed it smile All is working as it should be (so far, anyway)