Jump to content

Host headers and CNAME


jcanker

Recommended Posts

I currently have an IIS 6 webserver that is hosting several websites and I've got the host headers configured properly for all of them.

 

Separate from that, I am experimenting with a web app for some local non-profits that will help them organize their vertical data managment between them all. 

 

As part of this, each org will have the ability to have the system create a home page for them on the fly based on templates.

 

Given that context, THE QUESTION IS:

If they choose to use that template-based page as their new home page and forgo their existing webpage by creating a CNAME at their registrar, will I have to configure a new host header for each of those domains, or will the DNS that handles that domain send it through?  In other words, will it look to my IIS server as the ALIAS www.OrganizationDomain, or as the ACTUAL URL www.mydomain.com/organizationTemplatePage?

Link to comment
Share on other sites

DNS and HTTP are separate, though related. Which means two things:

1. Even if www.example.com resolves as a CNAME to www.website.com, the hostname is still "www.example.com". You only need to support the URLs people are using (which does often mean both names, but that's separate from the issue).

2. You cannot have a domain name resolve to a URL, so your organizationdomain.com -> mydomain.com/orgTemplatePage example doesn't make sense.

Link to comment
Share on other sites

Bah....it seems to me that back when angelfire, AOL, and such sites were popular for hosting personal webpages, there was a way to direct your registered domain to your "Home" folder, even when the url was something like userwebs.aol.com/~thisuser.  How was that done?  I thought it was through creating a DNS alias at the registrar.  I never actually went through with the process myself, but I seem to remember reading into before deciding to just start hosting my own server.

 

I suppose if nothing else I can blow the dust off of a batch script that creates host headers in IIS by command line, have it point to a common landing page that uses document.window.href to get the url that was typed in and then let jquery redirect to the page the loads the template for that organization based on the url.  >Sigh< didn't want to have to go through all that, but oh well.

 

Thanks for the response. 

Link to comment
Share on other sites

... a way to direct your registered domain to your "Home" folder, even when the url was something like userwebs.aol.com/~thisuser.  How was that done?
Apache has a module home_directories which does the URL to home directory mapping you showed.  I don't know if IIS has anything similar.

 

 

Link to comment
Share on other sites

Bah....it seems to me that back when angelfire, AOL, and such sites were popular for hosting personal webpages, there was a way to direct your registered domain to your "Home" folder, even when the url was something like userwebs.aol.com/~thisuser.  How was that done?  I thought it was through creating a DNS alias at the registrar.  I never actually went through with the process myself, but I seem to remember reading into before deciding to just start hosting my own server.

Those are the per-user things Doug hinted to. You, as thisuser, didn't have anything to do with the userwebs subdomain - AOL managed the server and all that. They would set it up so that anything userwebs.aol.com/~foo (a fairly traditional per-user path setup) would point to your files at /home/foo/public_html (or whatever).

 

I suppose if nothing else I can blow the dust off of a batch script that creates host headers in IIS by command line, have it point to a common landing page that uses document.window.href to get the url that was typed in and then let jquery redirect to the page the loads the template for that organization based on the url.  >Sigh

That... doesn't sound like a good solution. Can you not edit the website code to render the appropriate pages according to the HTTP_HOST value? Very simply,

id | hostname                   | path
---+----------------------------+---------
1 | www.example.com            | example
2 | www.website.com            | website
3 | www.organizationdomain.com | mydomain
4 | www.mydomain.com           | mydomain

 

define("DOMAINPATH", "/home/%s/public_html");

if (preg_match('/^[a-z0-9][a-z0-9.]*[a-z0-9]$/i', $_SERVER["HTTP_HOST"])) {
$domain = mysql_fetch_row(mysql_query("SELECT path FROM domains WHERE hostname = '{$_SERVER["HTTP_HOST"]}' OR hostname = 'www.{$_SERVER["HTTP_HOST"]}'"));
if ($domain) {
	$docroot = sprintf(DOMAINPATH, $domain[0]);
	if (is_dir($docroot)) {
		showdocument($docroot, $_SERVER["REQUEST_URI"]);
		return;
	} else {
		// host and domain exists but there's nothing to show
	}
} else {
	// no host/domain here
}
} else {
// either
// (a) the webserver accepted an invalid hostname, or more likely
// (b) the regex above is too strict and needs to be loosened a little
}

Link to comment
Share on other sites

That would be a more elegant solution, but I need the host headers to be configured for IIS to send the user to the right defined website in the first place.  This is sitting on an IIS server that is hosting multiple sites beyond this one, so I can't just have all http requests sent to one directory for PHP to get the HTTP_HOST. 

 

The issue isn't getting the host URL into PHP so much as it is creating, on-the-fly (e.g. minimal interaction from me), the ability for a cub scout troop to tell the system, "We have a registered domain, we want to point it to the dynamically created template site that uses the DB backend, and we'll point the DNS A record here.  The domain is "www.mypack333.net"

 

Unless I'm missing something, when a user types www.mypack333.net and the registrar's DNS server points it my way, IIS won't know what to do with it unless one of the configured websites has a host header for that domain, right? 

Link to comment
Share on other sites

Right, but it could have a default website it serves for hostnames it doesn't recognize.

 

So yes, if these are all separate websites with separate codebases and whatever then you'd probably need to create applications for each site. I think WMI is the way to go to script the right commands to IIS but I'm not familiar with it enough to be of any help there.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.