I want to rewrite urls to the www subdomain if the user omits it, i.e. example.com/something.html to www.example.com/something.html
The config below doesn't work, user remains on example.com. There's probably missing something very simple...
<VirtualHost *:80>
DocumentRoot /data/domains/example.com/www/public
ServerName www.example.com
ServerAlias example.com
# ErrorDocument 404 /index.pl page_not_found
# CustomLog /logs/apache/example.com/access_log combined
# RedirectMatch 301 ^(.*)$ http://www.example.com/
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} ^!example.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
</IfModule>