Why do sites still use the www subdomain? Some people, including most of us here at Plexus, think that it's deprecated. It's really only a subdomain, and there's absolutely no reason that it should still be used. But, I don't want to get into an argument about whether it's needed or not, I'm just going to show you how to redirect the www subdomain to no subdomain.
All you have to do is add the following lines to your .htaccess or .conf file:
# Redirect www.site.com to site.com with 301
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
That's it!
In the interest of fairness, I've decided to also show you how to redirect no-www to the www subdomain.
# Redirect site.com to www.site.com with 301
RewriteCond %{http_host} ^site.com [nc]
RewriteRule ^/(.*)$ http://www.site.com/$1 [r=301,nc]
Remember, with great power comes great responsibility. With that said, you should NEVER use that second code sample unless you absolutely have to (ie when Firefox gives an error about the security certificate only being valid for www.site.com).



