Upgrading to https - Lost all internal links

Re: Upgrading to https - Lost all internal links

by Ken Task -
Number of replies: 8
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