Every website used to be like “www.example.com”. Now I rarely encounter this “www.”. Why did it even exist and where has it gone? I also used to run into websites with legitimate domains, but “ww1.” instead of “www.”, these were probably phishing sites, but how did this actually work on top of legitimate domains?


Hey something I can answer!
TLDR: Because most owners of domains want their emails to have the same root (e.g.: [email protected] as the email and acme.com as the website)
TLDR word salad: RFC rules restricts root domain CNAME records from coexisting with other DNS record types. Early internet bypassed this by pointing the website to subdomain www.example.com with a CNAME record; while hosting MX record at the root example.com Modern dns services have CNAME flattening which dynamically responds to an A record query at the root example.com with multiple ips
Also DNS is complicated
Some of the comments here describe the results of what happened but do not touch on the reason behind why www was common and why it is not anymore
The reason is very boring: because the rules say so. Specifically https://www.rfc-editor.org/info/rfc1034/ “If a CNAME RR is present at a node, no other data should be present; this ensures that the data for a canonical name and its liases cannot be different.”
To discuss this further we need to breakdown what is part of the url in the first place so we don’t mix things up. e.g. https://www.google.com/
https --> specifies the protocol here its http encrypted over TLS (SSL if your old)
: --> separates the protocol from the rest of the url
// --> fun hold over https://archive.nytimes.com/bits.blogs.nytimes.com/2009/10/12/the-webs-inventor-regrets-one-small-thing
www --> subdomain
google.com --> root domain
.com --> top level domain https://en.wikipedia.org/wiki/List_of_Internet_top-level_domains
Now for some common DNS address types you are probably already familiar with are
A records (amazon.com translates to ipv4 98.87.170.71)
AAAA records (google.com translates to ipv6 2607:f8b0:4004:c1f::71)
MX record (tells where your email goes to)
CNAME record (points to another DNS record name - usually an A record)
So why does a domain restriction on CNAME interfere with a website?
Because most owners of domains want their emails to have the same root.
And the rules do not allow for the root domain name to have both a CNAME and a MX record
For example, to have [email protected] work.
A top level MX record for amazon.com must be published.
If an MX record for amazon.com exists CNAME can not exist.
So in the early days of the internet, a compromise standard was made.
MX records live at the root (eg: amazon.com) to direct mail for [email protected]
CNAME records live at www. subdomain (eg: www.amazon.com) to direct web traffic
Why not just drop the CNAME at the root?
Use MX for mail at the root and A record at the root for website!
This will work perfectly fine actually. There’s nothing functionally wrong with this.
In fact you can have your root A record round robin to several ips.
So your traffic can be roughly distributed at the DNS level across a few computers.
But this is generally a bad idea (without DNS health checks and other newer fancy things)
Because the actual computer behind your ip will inevitably crash, or update, or die, or reboot.
And now your website is fully down (1 ip) or partially down (1/3 of all traffic for example if you published 3 ips)
Why use CNAMEs at all?
Usually the CNAME record will point to some sort of load balancer. Think of this as router, it takes traffic in and sends it down to individual computers. If a computer dies, it takes it off from the available pool of computers; so that your traffic will hopefully live (session cache layer, etc, etc)
So in the old days DNS looked like this
MX record --> mail
CNAME record --> A record load balancer ips --> fleet of computers with internal ips added and dropped by lb
How does modern internet get on with root web traffic?
Some smart people got tired of typing www all the time so they invented CNAME flattening (DNS flattening) The DNS service provider, will dynamically update, and serve a fleet of individual ips as A records to the root domain lookup.
So now DNS looked like this
MX record -> mail
A record that keeps updating -> load balancer ips -> fleet of computers internal ips added and dropped by lb
Isn’t that similar to old days? Why don’t I just update my A records myself in the old days? Wouldn’t that be the same?
That’s actually exactly the same. The only problem with doing it yourself in the old days is DNS is hard.
DNS is basically a globally distributed cache managed at different layers by different people.
You COULD update the A records constantly yourself. You can even set your own record TTL to be 0 or 60seconds. However, random guy halfway across the world using budget ISP will not see your DNS update propagate to them for a few hours, sometimes 24 hours in worst case scenarios.
Modern DNS service providers (cloudflare, aws route53, etc, etc) has their own DNS hosted nodes distributed across the world for you so they auto update the records constantly for you to ensure no stale DNS hits if possible.
Practical Validation:
Since DNS is public you can run some queries yourself to see how DNS is managed by large companies
I’ll use amazon.com as example root MX record: https://mxtoolbox.com/SuperTool.aspx?action=mx%3Aamazon.com&run=toolpage
root A record: https://mxtoolbox.com/SuperTool.aspx?action=a%3Aamazon.com&run=toolpage
root CNAME record: https://mxtoolbox.com/SuperTool.aspx?action=cname%3Aamazon.com&run=toolpage
subdomain CNAME record: https://mxtoolbox.com/SuperTool.aspx?action=cname%3Awww.amazon.com&run=toolpage