Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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.

So, to clarify, is it possible to have http://foo.com/ in the address bar while http://www.foo.com/ is actually being accessed?

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.

share|improve this question
    
Are we talking from the perspective of your own website, or all websites in general? –  Thomas Oct 5 '09 at 0:36
    
Yes it is possible - but can you confirm your OS and webserver? –  Coops Oct 5 '09 at 19:17
    
Yeah, one sec. I'll edit the post. –  Nathaniel Oct 5 '09 at 19:18
    
So are any of these answers going to work with shared IP hosting, like NearlyFreeSpeech.NET uses? –  Nathaniel Oct 8 '09 at 23:04
add comment

8 Answers

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.

In Apache, that would look like:

NameVirtualHost *:80
<VirtualHost *:80>
ServerName foo.com
ServerAlias www.foo.com
# Virtual host document root, logging, other configuration here
</VirtualHost>

You will also need DNS for both foo.com. and www.foo.com. to resolve to the same address.

share|improve this answer
add comment

I would comment, if I were allowed to.

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.

share|improve this answer
add comment

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.

share|improve this answer
    
Right. Thanks, good answer. –  Nathaniel Jul 9 '10 at 3:45
    
+1 for first relevant answer –  zildjohn01 Aug 31 '10 at 19:40
add comment

You could rewrite the url if it includes www.

Something along the lines of:

RewriteEngine On
RewriteCond %{HTTP_HOST}   ^www\.NearlyFreeSpeech\.NET [NC]
RewriteCond %{HTTP_HOST}   !^$
RewriteRule ^/(.*)         http://NearlyFreeSpeech.NET/$1 [L,R=301]

Not entirely sure that'll work out of the box but should be close.

share|improve this answer
add comment

Independent of which domain you choose - keep in mind to be consequent with it. Indexing from search engines are affected by your choice.

i.E. Google: http://www.google.com/support/webmasters/bin/answer.py?hl=en&answer=44231

share|improve this answer
    
Like above the 301 redirect will help indexing. –  Xorlev Oct 5 '09 at 21:51
add comment

At the main page of example.com, you can show the site www.example.com inside an iframe, so while the user goes to and sees example.com, the cookie will come from www.example.com.

share|improve this answer
    
Hmm, nice thinking. That may possibly wreak havoc with CSS, though. –  Nathaniel Oct 10 '09 at 22:16
    
I don't see how it can break CSS ? –  hayalci Oct 11 '09 at 12:32
add comment

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.

share|improve this answer
add comment

Yes, it's possible, and I recommend it.

You probably want to add a permanent redirect so that "example.com/*" redirects to "www.example.com/". You don't say what web server you use, but it should be easy enough in any one of them.

share|improve this answer
    
Actually, that's now quite what I wanted to do. I want to have foo.com when foo.com is being accessed. –  Nathaniel Oct 5 '09 at 19:12
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.