Getting Rid of www [en]

[fr] Une recette pour faire disparaître magiquement ce satané "www" des noms de domaines que j'héberge...

I personally hate having “www” in front of a domain name. It’s redundant. If we’re visiting a website, we’re on the web anyway. It also brings no end of problems when people start writing for the web and creating links, because they think that what makes something a “website address” is the “www” in front if it, instead of “http://”. That’s how they end up with links like “http://example.com/www.yahoo.com” on their sites. But I digress.

On [one of the sites I manage](http://cafecafe.ch), we have a restricted members-only area. However, our users started reporting that when they used “www” in front of the domain name, they were being asked for the password twice. I tried myself, and I was simply asked for the password *ad aeternam*. Probably a server configuration glitch somewhere.

Anyway, I decided the simplest solution was to redirect all “www” requests to the non-www domain. I know I had that in place for CTTS at some point, but the setting must have got lost at some point. Instead of [sticking rewrite rules in .htaccess as no-www.org suggests](http://no-www.org/faq.php), I modified my vhost configuration slightly so that it looked like this:

ServerName example.com
DocumentRoot /home/example/www/
ErrorLog logs/example-error
CustomLog logs/example-access combined

ServerName www.example.com
Redirect permanent / http://example.com/

Try it!

[http://www.cafecafe.ch/](http://www.cafecafe.ch)

*Many thanks to those who gave suggestions and nudged me along the way to this solution.*

Similar Posts: