'Differences & benefits between HTTPS .htaccess Redirects examples

In the past I've always used the following code to force redirect to https:

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

I since renewed my hosting and ran into some issues with SSL. I was advised to use the following:

RewriteEngine On 
RewriteCond %{SERVER_PORT} 80
RewriteCond %{HTTP_HOST} ^(www\.)?coolexample\.com
RewriteRule ^(.*)$ https://www.coolexample.com/$1 [R,L]

As per this guide.

What's the difference here, and are there any benefits to using a specific version?

I've checked similar questions, such as this, but doesn't help with these examples. Thank you.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source