aspose file tools*
The moose likes Sockets and Internet Protocols and the fly likes how does a website know what subdomain a request comes from Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "how does a website know what subdomain a request comes from" Watch "how does a website know what subdomain a request comes from" New topic
Author

how does a website know what subdomain a request comes from

Tim Sparg
Ranch Hand

Joined: Dec 29, 2006
Posts: 40
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?


    There is no insanity so devastating in man's life as utter sanity
    Joe Ess
    Bartender

    Joined: Oct 29, 2001
    Posts: 8997
        
        9

    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.


    [How To Ask Questions On JavaRanch]
    Tim Sparg
    Ranch Hand

    Joined: Dec 29, 2006
    Posts: 40
    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

    Joined: Oct 29, 2001
    Posts: 8997
        
        9

    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

    Joined: Apr 16, 2008
    Posts: 2187
    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.
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: how does a website know what subdomain a request comes from