Alex Rivera | Logout

apache redirect from non www to www

Asked 2009-07-08T20:22:23.407
243

I have a website that doesn't seem to redirect from non-www to www.

My Apache configuration is as follows:

RewriteEngine On
### re-direct to www
RewriteCond %{http_host} !^www.example.com [nc]
RewriteRule ^(.*)$ http://www.example.com/$1 [r=301,nc] 

What am I missing?

Edit
Report

1 Answer

56
<VirtualHost *:80>
    ServerAlias example.com
    RedirectMatch permanent ^/(.*) http://www.example.com/$1
</VirtualHost>
answered 2009-07-08T20:32:05.307

Your Answer