I was told to ask on Server Fault when I asked on Super User, and that makes a lot of sense to me, so here it is.

I like the look of no www but am somewhat worried about drawbacks, such as shared cookies across the root and all subdomains (not that I actually know anything much about cookies at the moment, but I do want to futureproof).

My guess is this might possibly be possible through some sort of alias type thing. But I could be wrong, so here I ask.

Edit: I'm planning to host with NearlyFreeSpeech.NET. The server is Apache and I would guess the OS is some flavor of Linux.

Edit 2: So do you actually understand what I mean? What I'm looking for is this: when one browses to the site, http://foo.com/ is what they see in the address bar but http://www.foo.com/ is what is being accessed. I have to say Xorlev's answer looks the closest but will it work out, considering potential cookie issues and that I'm going to be using shared IP hosting.

8 Answers
8

Yes. Depending on the web server configuration, you either need to not do anything (if using IP-based virtual hosts or not using virtual hosts at all) or configure a name-based virtual host with a ServerName and ServerAlias directive.

Charles' answer is correct. One thing you might want to do a little differently. I normaly set the foo.com DNS entry as an A record to the IP and the www.foo.com entry as a CNAME record to foo.com. So In case your IP changes, you don't need to change both. But that's a small detail.

I don't think any of these answer it. Your main problem is going to be with cookies: if you set them at example.com, the browser will send them in for *.example.com, including domains that serve static content such as images.example.com or static.example.com. Your problem then is that an interim cache, such as a caching proxy or even a browser, may refuse to cache anything that was requested with cookies. This sends the load back to your primary server.

Many people recommend having a www subdomain so that you can serve your cookies from there and not have them sent back for your static subdomain. Unfortunately, if you do this, you cannot get a no-www URL. My recommendation is to use an entirely different top level domain for static content:

Main: example.com
Static: examplestatic.com

Look at twitter.com as an example. They don't have a www and they serve images and CSS from twimg.com.

I don't know about the cookies, but as far as accessing your web site via http://example.com and http://www.example.com is concerned, you need to add a domain A record to your DNS zone that points to the ip address of your web server. You may or may not have to add hostheaders to your web site for this to work, I don't remember and don't have a server handy to check.