Additionally, to force all web traffic to use HTTPS, you can also configure your virtual host file. Normally, there are two important sections of a virtual host configurations if an SSL certificate is enabled; the first contains configurations for the non-secure port 80.
The second is for the secure port 443. To redirect HTTP to HTTPS for all the pages of your website, first open the appropriate virtual host file. Then modify it by adding the configuration below.
NameVirtualHost *:80
<VirtualHost *:80>
   ServerName www.yourdomain.com
   Redirect / https://www.yourdomain.com
</VirtualHost>
<VirtualHost _default_:443>
   ServerName www.yourdomain.com
   DocumentRoot /var/www/html
   SSLEngine On
# etc...
</VirtualHost>Save and close the file, then restart the HTTP sever like this.
$ sudo systemctl restart apache2