Why is the "www." sometimes necessary? [duplicate]

Solution 1:

It depends on how DNS is setup. If they do not have an A (or host) record at math.cmu.edu pointed at the IP of the web server, then the site will be inaccessible without adding the "www" in front.

There is no standard that says a site needs to be accessible without the "www", but it has been a common practice for a long time since the web is so prevalent.

Solution 2:

There is a VERY good reason why WWW exists for domain names, and it is: cookies!

If you set a cookie on example.com then it is accessible from www.example.com, but also from admin.example.com and images.example.com. By accessing your website through www.example.com and setting cookies for www.example.com that means that your cookies are not going to be passed to admin.example.com.

Sometimes you want this. Sometimes you don't. You need to decide straight up if you need cookies accessed across subdomains on your site.

Case in point, we started running our website on www.example.com. When they needed to add SSL to the website, some smart cookie decided to put the SSL on secure.example.com. Now when users move from www.example.com to secure.example.com their cookie is lost and so is their login information.

That said, I can't see any good reason why you would have www.secure.example.com

Solution 3:

there is no reason. domain names are arbitrary (although there are some well-known conventions like www. for webservers, ftp. for ftp servers, mail. or smtp. or mx. for mail servers etc).

www.example.com and example.com may refer to the same machine (via A records or CNAME) or they may point to completely different machines.

in the latter case, the only way to have http://example.com/ and http://www.example.com/ get to the same site is to have a httpd running on example.com that issues a redirect to www.example.com

(it's not unusual for this redirection to occur even when two or more domains point to the same site & machine - e.g. apache's "UseCanonicalName on" and mod_rewrite to redirect requests for the non-canonical name to the canonical name for the site)