Date: 2005-04-20 11:30:00
Tags: web
the accursed www

The common www part of web server addresses has annoyed me for a long time. It's unnecessary, ugly, and annoying to pronounce. There is even a site, no-www, that is dedicated to the effort of eliminating the www wart on web addresses.

[info]dbaker today pointed me to an easy way to eliminate the www using Apache. Instead of using the cumbersome mod_rewrite as suggested on the no-www site, do something like this:

<VirtualHost *>
    ServerName www.example.com
    Redirect permanent / http://example.com/
</VirtualHost>

Then, remove the ServerName www.example.com line from the real server configuration section. This assumes that you are using NameVirtualHost, which isn't the default but probably should be.

This configuration quietly redirects any URL with www to the corresponding URL without. This improves the way your URL looks, improves search engine efficiency, and promotes world peace. Well, maybe not that last thing.

[info]nugget
2005-04-20T16:45:36Z
I told you to do this a year ago! :)

dbaker's example is poor, though. what you want to be able to do is redirect all hits properly, as in:
            
<VirtualHost *:80>
ServerAdmin nugget@slacker.com
ServerName www.slacker.com
ServerAlias ww.slacker.com
ServerAlias members.slacker.com

RedirectMatch permanent /(.*) http://slacker.com/$1
</VirtualHost>

That will properly redirect deep links to the non-lame URL instead of just sending everyone to the main page.
[info]ghewgill
2005-04-20T16:49:01Z
That's what I thought the Redirect option would do too, until I tried it. See for example: http://www.hewgill.com/links.html

And I'm a slacker, so although you mentioned this a year ago, I just got around to it today. :)
[info]nugget
2005-04-20T16:52:02Z
Nutty, I had no idea. How unexpected.
[info]ghewgill
2005-04-20T16:56:26Z
Indeed, it's actually documented this way:

"URL-path a (%-decoded) path; any requests for documents beginning with this path will be returned a redirect error to a new (%-encoded) URL beginning with URL."

Good to know. My mod_rewrite is broken right now for some reason, so this was useful. :)
[info]dbaker
2005-04-20T17:11:33Z
I'll take that as a formal apology. :)
[info]swimathon : Save www
2005-04-25T11:06:26Z
www is useful. In the same way ftp. dns. mail. archie. etc identify the main purpose of an address, so does www. It also prevents people from having to type in a URL instead of just an address as many systems will easily identify something beginning with www. as being a HTTP url to follow and will automagically link them.

At least this doesn't condone abandoning the www. address I guess.
[info]ghewgill : Re: Save www
2005-04-25T17:13:41Z
Gmail recognizes non-www urls such as hewgill.com as clickable. That's good enough for me.
[info]leiju
2005-04-26T15:53:06Z
awwwww and no world peace?

*snif*

brilliant stuff by the way :)
[info]hoyhoy
2005-05-02T21:03:08Z
Hmmmm, I tried this on my server, and I get an error with Firefox!
"Redirection limit for this URL exceeded". OMGWTF!?

DocumentRoot /var/www/html/involution
ServerName www.involution.com
ServerAlias hoyhoy.org
ServerAlias www.hoyhoy.org
RedirectMatch permanent /(.*) http://involution.com/$1

Greg Hewgill <greg@hewgill.com>