You must activate the option AllowOverride All to use .htaccess file. Also, you can add the Rewrite rules inside the Directory in the conf file like the below example or on your .htaccess file.
<Directory "/srv/www/htdocs">Options -Indexes +FollowSymLinksAllowOverride AllRewriteEngine onRewriteCond %{SERVER_NAME} =example.com [OR]RewriteCond %{SERVER_NAME} =www.example.com RewriteRule ^https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]Require all granted</Directory>
I have changed my Directory in Conf file to only:
<Directory "/srv/www/htdocs"> AllowOverride All Require all granted</Directory>
And inserted in .htaccess the following only:
RewriteEngine onRewriteCond %{SERVER_NAME} =www.example.comRewriteRule ^https://www.example.com%{REQUEST_URI} [END,NE,R=permanent]
So If this don't work contact your host to add AllowOverride All only.