I have the following:
<VirtualHost *:80>
DocumentRoot /var/www/webmaster/example.com/web
ServerName example.com
ServerAlias www.example.com
ServerAdmin webmaster@example.com
<Directory /var/www/webmaster/example.com/web>
Options +ExecCGI
AllowOverride All
Require all granted
</Directory>
RewriteCond %{HTTP_HOST} ^example.com [NC]
RewriteRule ^(.*) http://www.example.com$1 [last,redirect=301]
</VirtualHost>
However when I view http://example.com it stays at http://example and does not go to http://www.example.com
This is even after trying all the other mentioned posts such as: apache redirect from non www to www