Upgrading to https - Lost all internal links

Upgrading to https - Lost all internal links

by Russell Thomson -
Number of replies: 14

Moodle 3.8.1+ (Build: 20200117)

I change the config file to https and in the http Security I ticked 'Use https for logins' and 'Secure cookies only'. I ran the HTTPS conversion tool and when I run Moodle I find I have lost all the internal links. During the conversion I got the following screen. Can anyone help? Thanks and regards

https


Average of ratings: -
In reply to Russell Thomson

Re: Upgrading to https - Lost all internal links

by Howard Miller -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
Can you define what you mean by 'lost'? What is the error message? What is logged in your web server's error log?

I did have a quick look at your site and found a couple of links that appear not to have converted. That's odd. This script is normally reliable. 
In reply to Howard Miller

Re: Upgrading to https - Lost all internal links

by Howard Miller -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
Just to add... the first one I noticed was an iframe. Are these broken external links really on your Moodle site. They're not a link to an external page that links back to your Moodle site are they?
In reply to Howard Miller

Re: Upgrading to https - Lost all internal links

by Russell Thomson -

Sorry for the lack of precision: the links are broken. I don't have any external links; they all relate to the resource 'pages' which include additional information or answers.

In one of Emma's posts she said to run yoursite.com/admin/tool/replace/index.php. When I did that, nothing happened, it went to the home page.

You mentioned that you looked at my page and found that a couple of links that appear not to have converted. In the hosting service I uploaded a backup I took on Friday which I could work on, so I tried it this morning and when it didn't work I moved back to the database I use for work so that that students could work. Maybe you looked after I changed back. Tomorrow I'll upload the database again so that it is a 'new' database to update again.

Before I delete the database I'll try Ken's suggestion: moodlecode/admin/tool/httpsreplace/cli/ 

If that doesn't work I'll upload the test database again, change the config file and tick 'Use https for logins' and 'Secure cookies only'. Maybe I don't need the HTTPS conversion tool as I don't have any external links.

Anything else I should do?

Regards

 


In reply to Russell Thomson

Re: Upgrading to https - Lost all internal links

by Ken Task -
Picture of Particularly helpful Moodlers

When I checked your site, it showed using LetsEncrypt for certs.  In their recommendations, once cert files are acquired and site is responding, they recommend setting up a redirect so that any request ... http:// or https:// headed to your site is automagically changed to https://.

That's an extremely good idea these days considering more and more attacks via web are on the rise.  Many site providers now offer a CDN (CloudFlare) which is both for caching and for protection.  Many strongly suggest setting up a WAF (web application firewall) like mod_security that sits in front of any web based application ... WordPress, Joomla, and even Moodles could use the 'extra protection'.

Would strongly suggest *NOT* using option https for login only ... make your site 100% https and be done with it.

The httpsreplace tool I think was designed for moodle sites that had originally been set up using http:// ... there fore all *internal* links inside of Moodle would use the CFG variable for the site (http://youresite/ to build/concactate ALL internal links.   The search then, if site was functioning as http://site/ should have been search for 'http://yoursite/' ... note the protocol in front and the 'trailing slash'.   Replace with 'https://yoursite/' ... again ... note the protocol in front and the 'trailing slash'.

And a caution ... before your next attempt, make sure you have an SQL dump - date/time stamp the sql dump file names if site is functioning as http://.  You could in-advertently have a messed up sql dump and restoring it could complicate the issue.   Such that your ONLY alternative is to use a true text editor ... NOT Word or other like it ... but a *true* text editor (like nano on CentOS) to search for all links 'http://site/' and replace with 'https://site/' ... then use that raw edited sql file to import into a new DB for the moodle.

My $100.00 tip!

'SoS', Ken


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

Re: Upgrading to https - Lost all internal links

by Russell Thomson -
Hi Ken,
I used the tool /admin/tool/httpsreplace/index.php/ and all the pages changed to https but the links from quizzes to pages were broken. When I click on a link it just takes me back to the home page.
After the replace finished I got the following screen:
https1
Tip. Thanks and regards

money



In reply to Russell Thomson

Re: Upgrading to https - Lost all internal links

by Ken Task -
Picture of Particularly helpful Moodlers

"links from quizzes to pages were broken" ... so not fixed, right?

If not fixed for quizzes to pages ... two choices ... edit raw sql dump ... if you can find the old http:// url's in there - search and replace ... etc.

OR

Set your web service to redirect all http request to https

https://www.google.com/search?client=firefox-b-1-d&q=redirect+http+to+https

'SoS', Ken

In reply to Ken Task

Re: Upgrading to https - Lost all internal links

by Russell Thomson -

Hi Ken, 

I'm making progress. I managed to do it once with an old database but I haven't managed to replicate it. I think the order of doing things might make a difference. I typed in /admin/tool/httpsreplace/index.php/ and then uploaded the config file, which I had changed to https:, and then I started the update. I got the first screen (only the second time I had got it) and after proceeding with the conversion I got the Error message, second screen. Any ideas?

convert 

error https

As usual, thanks and regards,

Russell

In reply to Russell Thomson

Re: Upgrading to https - Lost all internal links

by Ken Task -
Picture of Particularly helpful Moodlers

In your second screen shot ...

last line ... it shows /admin/tool/replace/index.php
not httpsreplace.

/admin/tool/httpsreplace/ shows this screen text when one accesses initially:

"Upgrade externally-hosted content URLs to HTTPS

When a site is moved from HTTP to HTTPS, all embeded HTTP content will stop working. This tool allows you to automatically convert HTTP content to HTTPS. Before performing the conversion, content will be scanned to find any URLs which may not work after conversion. You may want to check each one has HTTPS available, or find alternative resources.
"

with a links to docs for it:

https://docs.moodle.org/38/en/HTTPS_conversion_tool

Your moodle site is in an /e-learning/ subdirectory so when using the url  line to navigate use site/e-learning/ in front.

Also ... earlier response ... you said you'd try the CLI script.   Did you?

cd /path/to/site/admin/tool/httpsreplace/cli/ [ENTER]

then execute:

php url_replace.php [ENTER]

That will bring up a help screen which shows:

"Examines DB for non-https src or data links, and lists broken links or replaces all links.
Options:
-h, --help            Print out this help
-l, --list            List of http (not https) urls on a site in the DB that would become broken.
-r, --replace         List of http (not https) urls on a site in the DB that would become broken.
--confirm             Replaces http urls with https across a site's content.
Example:
$ sudo -u www-data /usr/bin/php admin/tool/httpsreplace/cli/url_replace.php --list

Issuing:  php url_replace.php --list

will show if there are any urls that need converting.

'SoS', Ken



In reply to Ken Task

Re: Upgrading to https - Lost all internal links

by Russell Thomson -

I did as you suggested and I got the following screens:

httpsreplace

Not exectuted

How do I execute the command lines?

In reply to Russell Thomson

Re: Upgrading to https - Lost all internal links

by Ken Task -
Picture of Particularly helpful Moodlers

CLI means command line ... only.   Cannot be executed via a web browser.

Run them via ssh shell - login to server using Putty on PC or Terminal on a Mac or if you have Webhosting Management (WHM) where you host there is a Terminal icon (or is present with most providers and if you have that type of account with provider.

Once you are logged on you will probably find yourself in your home directory ... and will have to change into:

cd public_html/english/e-learning/admin/tool/httpsreplace/cli/

ls to list what's there ... you should see: url_replace.php

To execute: php url_replace.php [ENTER]

That will bring up help screen.   Option to command --list should list all the script finds that needs converting:

php url_replace.php --list

Just follow the help screen example, but change the values/variables to match your server.

If you cannot do this, maybe you can ask your providers help desk folks to do it for you.

Good luck!

'SoS', Ken


In reply to Ken Task

Re: Upgrading to https - Lost all internal links

by Russell Thomson -

I have converted all the URLs on my webpage to https:\\ but I am unable to edit the quizzes. Screenshot. Also, when I click on a link, the URL appears but quickly changes to the dashboad URL. Any ideas?

Editing an embedded image

In reply to Russell Thomson

Re: Upgrading to https - Lost all internal links

by Ken Task -
Picture of Particularly helpful Moodlers

Is https:\\ a typo here?

Since you've successfully converted all http:// to https:// links this question might be a different issue.

Suggest turning on debugging to see if there is anything your moodle can tell us.

And if this is a new issue, suggest you post a new posting with appropriate subject. ;)

'SoS'. Ken


In reply to Russell Thomson

Re: Upgrading to https - Lost all internal links

by Ken Task -
Picture of Particularly helpful Moodlers

In addition to Howard's ...

Please see:
https://docs.moodle.org/38/en/HTTPS_conversion_tool

IF you have ssh into your server, there is a cli (command line only) tool that will help correct situation in

moodlecode/admin/tool/httpsreplace/cli/

Info for how to use shown in URL above.

All sites should be using https:// now - all the time ... not just for login ... IMHO.

'SoS', Ken