How to redirect HTTP to HTTPS in WordPress?

Hi everyone, I'm definitely a novice when it comes to internet back-end things that they wanted to see if you could shed some light for me.

On the inside of WordPress I changed my general settings for both the URL of the site and the URL of WordPress from http to https. It seems to have worked, but if I type the URL with http, it does not automatically redirect to https as I thought.

Basically, the HTTP and HTTPS protocols work separately and return the same content of the page.

My friend tells me that I should use the following code in my .htaccess to set up a 301 redirect:
RewriteEngine On
RewriteCond% {HTTPS} disabled
RewriteRule ^ (. *) $ Https: //% {HTTP_HOST}% {REQUEST_URI} [L,R=301]

Is this information accurate and should I use this code?

Thanks for your contribution.