How to automatically redirect http to https?

I recently installed an SSL Certificate to "http://www.mywebsite.com" address and now I need to have all traffic go to "https://www.mywebsite.com" how do I do that? Here is what I have so far but it doesn't seem to be working.

.htaccess file:

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
  • Way out of scope for this forum, but does this help?

    If you want HTTP traffic to redirect to HTTPS, you can add this additional server block at the top of the file (replace the highlighted parts with your own information):

    server {
        listen 80;
        server_name example.com;
        rewrite ^/(.*) https://example.com/$1 permanent;