How does a Windows server distinguish between 2 host names being directed by DNS to the same IP address?

I started a new job recently. We have files.example.com pointing to x.x.x.x IP address. I got asked to direct git.example.com also to x.x.x.x in a way such that the server can distinguish which site the requests come from.

I did my best to understand for the past couple of hours by searching Google uncontrollably. I used ambiguous names for the sake of anonymity of the pages I am working with.

From what I got so far: the Windows server can be set up to do HTTPS redirects that have status codes. There is a log of these on the server. I found one post mentioning that the HTTP 1.1 protocol includes a header called host which specifies which particular page a client is trying to access. How do you have one IP address and many websites? - ServerFault

So if I understand correctly, the server can distinguish between the 2 domains based on these host headers?

I feel like this is not the complete answer. In this case, just setting up redirects on the server should suffice since the server can already distinguish between the 2 pages, or is there another way?

  • I changed the terminology you use from "page" to "host name". Two pages could be on the same host name, but your question if for when the two host names are distinct. Commented May 5, 2020 at 10:21
  • i changed your terminology from "redirect" to "directed to". A redirect is a user visible change in the URL. I don't think that is what you want. You want to set the two host names to use the same server, but not necessarily for users to be taken from one to the other. Commented May 5, 2020 at 10:22
  • Apologies for the mistakes, i am not sure what terminology to use yet but im learning, thank you for letting me know! :)
    – JDoe
    Commented May 5, 2020 at 10:30

1 Answer 1


If I understand your question, you're asking how the web server knows which domain to send the request to.

You are correct about host headers.

HTTP(S) 1.1 added host headers as a way for web servers to host more than one host/domain. When you make a request via your web browser, it sends a request via HTTP(S). The protocol includes both the IP address and the host name the client is requesting. Typically something like www.example.com or www.example2.com.

These names are resolved by DNS to an IP address so routers can forward the request to the correct server (Post Office). However, since a single server can host multiple services, we need a way to distinguish which mailbox on the server to put the request in. We use ports to identify which mailbox.

But, even if we put mail in the correct mailbox, we still need to know which person in the house the mail goes to. A typical browser request goes to port 80 (HTTP) or 443 (HTTPS), but once there, the web server reads further into the header to determine which person/domain to forward the request to. It's just like getting mail addressed to different people in your home. You read the address and say "This isn't for me, it goes to my roommate".

In Windows IIS, we can assign the same IP address to different web directories in the file system via bindings. So we might have a multiple directories on a our file system, each containing the files for each domain's web site. For example your web server might have the following directories, \example\default.html, example2\default.aspx, \example3\index.html. Using bindings we could assign example.com to \example, example2.com to \example2 and example3.com to \example3.

For the process of how you can do this in IIS see IIS and Bindings

  • This is exactly what i was looking to understand. Thank you.
    – JDoe
    Commented May 5, 2020 at 17:04
  • You are missing an important part: in case of HTTPS the connection happens on the IP and the TLS handshake starts before any HTTP stuff is exchanged, including headers. So the server has no way then to know which host (and hence associated certificate) it has to handle if there are more than one on the same IP. To resolve this, "Server Name Indication" aka SNI was invented, which is an extension of TLS. This allows the client, far before the HTTP(S) headers to transmit early in the TLS handshake which hostname it wants to connect to. Commented Jun 2, 2020 at 21:17
  • @PatrickMevzek good point. Thanks for expanding on this.
    – Trebor
    Commented Jun 3, 2020 at 2:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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