Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how does a website know what subdomain a request comes from

 
Tim Sparg
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
there are websites out there that have the following url schema
http://[uniquesubdomain].example.com

so in our example we will use these 2 urls.
  • http://companyA.example.com
  • http://companyB.example.com


  • When you go to http://companyA.example.com the logo for the company shows up on the landing page.
    The same happens when you go to http://companyB.example.com

    How does this work?

     
    Joe Ess
    Bartender
    Posts: 9319
    10
    Linux Mac OS X Windows
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    It's basically a trick with DNS. The first part of a fully qualified domain name refers to a host (like ftp.x.com or www.x.com). These hosts can be real (i.e. unique machines) or virtual (many hosts on the same server). Each host can serve its own unique content.
     
    Tim Sparg
    Ranch Hand
    Posts: 40
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    I've been browsing around trying to work this out - I think this is how it works, but then again I might be conpletely misdirected

    http://companyA.example.com resolves to myserver:765
    http://companyB.example.com resolves to myserver:234

    Either your application picks up what port the request is coming through and from there is able to serve unique content for the company/user
    OR
    You have some kind of proxy/filter sitting in front of your application that puts something into the http header like "companyCode", then your application is on the look out for the companyCode http header

    Does any of this sound roughly right?

     
    Joe Ess
    Bartender
    Posts: 9319
    10
    Linux Mac OS X Windows
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    There's probably many different ways to implement this functionality.

    Either your application picks up what port the request is coming through and from there is able to serve unique content for the company/user

    Your application, if it is a "normal" web application, is going to be mapped to a single port. It is more likely one would use virtual hosts to implement the proxy idea and forward to a content management system.
     
    Jimmy Clark
    Ranch Hand
    Posts: 2187
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Domain names are mapped to point to "physical" locations on a server machine, i.e. machine with web server. A DNS server handles the search and find operations.

    In regards to "knowing" which domain a HTTP Request came from, this information is in the HTTP headers of the request.

    To learn more about how this works, find material on DNS server operations and HTTP headers.
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic