What you want to do goes under the term Name Based Virtual Hosting
Technically what is going on is that the web browser resolves bar.that.com
to an IP address (e.g. 1.2.3.4
).
Then it sends an HTTP request to 1.2.3.4
.
The host does not normally know about the name which was used to address it.
An special feature of HTTP 1.1 however allows the browser to insert the host name into the HTTP header.
A typical HTTP header looks like this:
GET / HTTP/1.1
Host: bar.that.com
The web server then decides according to the contents of the Host:
header which pages to deliver.
Of course you have to tell it how to decide in it's configuration. For Apache see here, but any modern web server will have something similar.
Name Based Virtual Hosting is widely used, everytime you hear the term Shared Hosting, think of
Name Based Virtual Hosting.
HTTP 1.1 is around long enough so that all browsers in use support it.
Only very, very old browsers, like NCSA Mosaic, didn't support it.