views:

127

answers:

1

Is there an easy way (preferably with htaccess and mod_rewrite) to force the browser to always access a site with the www. prefix (adding it automatically where necessary?)

Thx.

+4  A: 
Rewritecond %{HTTP_HOST} !www.domain.com
RewriteRule ^/(.*)$ http://www.domain.com/$1 [R=301]

or maybe

RewriteCond %{HTTP_HOST} !^www.
RewriteRule ^/(.*)$ http://www.%{HTTP_HOST}/$1 [R=301]
jasonbar
It doesn't appear to work, as the site sits in a subdomain on the server. Is there a way to make it global?
DCD
@DCD, see update. If that isn't what you mean perhaps you can update your question with some more information?
jasonbar