Sam Brown

How to remove www from your domain name

Because of the popularity of my article on .htaccess Redirects from May 2005 I get emails quite often asking questions on how to use .htaccess to remove the www from a domain, or how to redirect from no-www to www. Here is some background information and how to do it.

WWW is depreciated

WWW stands for World Wide Web, which is a term that is seldom used anymore. The use of www in a domain name is redundant and time consuming, browsers automatically prepend all URLs with the http:// protocol which connects to the HTTP server for serving a sites files. Why then is there a need to type www as well?

Most decent web servers will display the exact same files at http://domain.com and http://www.domain.com. This is the most common solution, however you may want to use only one or the other.

Redirecting from www to no-www at your domain

Using some simple .htaccess trickery it is easy to redirect anyone visiting your site with the www. to http://domain.com. Simply adding the following to the .htaccess file in your root folder:

  1. RewriteEngine on
  2. Options +FollowSymlinks
  3. RewriteCond %{HTTP_HOST} ^www\.DOMAIN.com [NC]
  4. RewriteRule ^(.*) http://DOMAIN.com/$1 [L,R=301]
  5. Download this code: /code/want_no_www.txt

Redirecting from no-www to www at your domain

It is possible to do it the other way around as well, redirecting anyone visiting your site without the www. to http://www.domain.com:

  1. RewriteEngine on
  2. Options +FollowSymlinks
  3. RewriteCond %{HTTP_HOST} !^www\.DOMAIN.com [NC]
  4. RewriteRule ^(.*) http://www.DOMAIN.com/$1 [L,R=301]
  5. Download this code: /code/want_www.txt

Which method to use

It really is up to yourself which you use. What you must make sure of is that visiting with or without the www still displays your site, and that visiting one doesn’t result in an error message.

In my opinion WWW is pretty much invisible these days, it is so common that everyone has become accustomed to seeing it. Thus, having your site redirect from the www to just http://domain.com I feel looks better, is shorter to communicate and works just as well! For example visiting http://www.thesidepath.com always redirects to the no-www option.

PS. This is an old and well discussed topic on the internet, these are my thoughts and opinions and are written here to help inform my visitors to the .htaccess Redirects topic on how to successfully go about removing or redirecting to or from the www in a domain name.

Post a link to this on Twitter ↩

Comments

Chris 26 June 2007, 15:13 #1

I do think that the reason to the popularity of the “www” was because of different protocols that were used back in the days. It was used so that people didn’t get mixed up with other protocols such ftp (such as ftp.domain.com) . Because the web (and email) is so more widely used than FTP nowadays and virtual accounts all point to the same IP, there really is no use for the www. Though I still use it for stuff like business cards, since it’s a visual queue that it’s my web address rather than just have domain.com on the card. :)

Commenting has closed for this article. Feel free to me.

Sam Brown co-founded Iterate, and was previously VP of Design at Foursquare. Based in NYC.

DribbbleEndorseFacebookFoursquareInstagramTwitter