Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

I am trying to make a homemade HTTP server. It occurs to me, though, I never fully understood what you might call "relativity" among web pages. I have come across that www. is a subdomain, and I understand its original purpose. IT sounds like, in general, you would redirect (is that 301 or 302?) it to a... non-subdomain, sort of. As in, redirecting www.example.com to example.com.

I am not entirely sure how to make this work when retrieving files for an HTTP server though. I would assume that example.com would be the root, and www manifests as a folder within it. I am unsure. There is also the question of multi-level subdomains, e.g. subdomain2.subdomain1.example.com. It seems to me they are structured "backwards", where you go from the root left in folder structure. In this situation, subdomain2 is a directory within subdomain1, which is a directory in the root.

Finally, it occurs to me I might want a sort of global location. For example, maybe all subdomains still use an image as a logo. It makes more sense to me that there is one image, rather than each having a copy. In the same way, albiet more doubtfully, you might have global CSS (though that is a bit contrary to the idea of a subdomain in the first place), or a javascript that is commonly used. (more efficient than each having its copy and better for organization purposes). Finally, mabye you have a global 404 page. I think this might be the case where you have user-created subdomains (say bloggername.example.com), where example.com still has a default 404 when either a subdomain does not exist or page does not exists under a valid blogger.

I am confused on what the directory structure for this should be. To summarize: Should and how it have a global files not in a subdirectory, how should www. be handled, (or how a now www or other subdomain should be handled), and the pattern for root/subdomain, as well as subdomain within subdomains (order-wise).

Sorry this is multiple questions, but I feel at the root they are all related to the directory.

share|improve this question

2 Answers 2

www is almost never a sub-directory of the website document root. If it were, the web server would have trouble figuring out if it was supposed to be served as example.com/www or www.example.com

Rather, each domain or sub-domain that is hosted gets its own section in the web server's configuration file and that configuration defines a document root. On my webserver, all websites are stored in the directory /var/www and the directory structure for it might look like:

/var/www/
    example.com/
         index.html
    blog.example.com/
         index.html
    othersite.tld/
         index.html

If I am redirecting www.example.com to example.com, I would not even create an directory for it. Rather I would just put the instructions to perform that redirect in the web server configuration and not define a document root.

share|improve this answer

I think perhaps you have some terminology mixed up here, when you bind an IP to a website host on any web server, you should then define a default file system directory and document which then becomes the "root" of the website you are about to host. All other references from here can be relative, sub-domains need to then alias from either the same or new roots based on the DNS record resolving your IP to that domain name.

share|improve this answer
    
In my case, this is more of a test server, so no domain/DNS at this point. I think I get the concept of different roots, but in this case, are double subdomains (say, mpa.one.microsoft.com), would you have a different root for each one (in a way that mpa is not really in one, but seperate altogether, sort of like Java packages), or would you have, say, that root and folder for each subdomain from that subdomain? –  user3101220 Feb 1 '13 at 18:42

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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