Removing “www” From a Domain
Here’s what I do to remove “www” from my domain. I put this code in my .htaccess file:
- RewriteEngine On
- #Handle removal of “www”
- RewriteCond %{HTTP_HOST} ^www.YOURDOMAIN.com(.*)$ [NC]
- RewriteRule ^(.*)$ http://YOURDOMAIN.com/$1 [R=301,L]
A couple quick notes about this method if you want to use it as your own:
- In order to see/edit .htaccess, you may have to show “invisible” files in your FTP application.
- This only works on servers running Apache.
For more information, and a technical explanation of what each line does, read John Gruber’s post (and subsequent opinion of why one would want to do this) from May 2006.
no-www.org and yes-www.org have some interesting points in the debate on whether or not to use www in Web addresses. I personally like to accept traffic on www, then silently redirect to the non-www version.
§ Jon Bourne · 03 April 2007
Thanks for this tip! This will be extremely useful.
§ Will · 22 July 2007