To redirect all users to access the site with the 'www.' prefix:
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
To redirect all users to access the site without the 'www.' prefix:
RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC]
RewriteRule ^(.*)$ http://example.com/$1 [L,R=301]
Very similar to Apache. To redirect all users to access the site with the 'www.' prefix:
RewriteCond %{HTTP_HOST} ^example\.com$ [I]
RewriteRule ^/(.*) http://www.example.com/$1 [L,R=301]
To redirect all users to access the site without the 'www.' prefix:
RewriteCond %{HTTP_HOST} ^www\.example\.com$ [I]
RewriteRule ^/(.*) http://example.com/$1 [L,R=301]
© Alexey Busygin, 2008–2010. alexey@busygin.com