Help - Search - Members - Calendar
Full Version: HOWTO: "cp/webmail/etc.domain.com" Without Dedicated IP
The Planet Forums > Operating Systems > Microsoft Windows > Windows HOWTOs
BeHosts
(This is intended for use with Helm)

EV1 only give you 7 free IPs and I didn't want to waste them icon_wink.gif so I searched for a way to create global subdomains without:

• Having to use a dedicated IP for each one
• Creating them manually for each domain
• Any other labourious method icon_razz.gif

And I found one! IIS's "Default Web Site" handles requests for all domains on an IP that are not handled by another VHost. And with a little bit of PHP magic... we have global subdomains without extra IPs.

Heres what you have to do (assuming you don't actually use the default website):

• Open the IIS MMC, find "Default Web Site" in the list of domains. Properties -> Documents, add index.php and move it up to the top of the list.
• Goto the document root for the default website (c:inetpubwwwroot by default), and create a file called index.php.
• Put the following code in the file you just created:
[php]/* chris@onestopwebhosting.com */

$redirects = array(
"webmail" => array(
name => "webmail",
url => "http://webmail.onestopwebhosting.com"),
"mail" => array(
name => "mail",
url => "http://webmail.onestopwebhosting.com"),
"helm" => array(
name => "cp",
url => "http://cp.onestopwebhosting.com")
/* add more here, in the following format:
"friendly name" => array(
name => "subdomain",
url => "http://url.subdomain.points.to")
EG:
"phpmyadmin" => array(
name => "phpmyadmin",
url => "http://phpmyadmin.onestopwebhosting.com")
*/
);

$host = strtok($_SERVER['HTTP_HOST'], '.');

foreach ($redirects as $redirect) {
strchr($redirect['name'], '.');
}

foreach($redirects as $redirect) {
if (strcasecmp($redirect['name'], $host) == 0) {
$url = sprintf("Location: %s", $redirect['url']);
header($url);
}
}
?>
[/php]
• Change the URLs at the top of that code to point to your global webmail / Helm / etc install.
• Add any other global subdomains you want to the list in the code using the format described in it.
• Check the permissions on index.php are correct. The easiest way to do this is to reset them. Goto the properties of the folder its in, goto the Security tab, click advanced, check "Replace permission entries on all child objects with entries here that..." and then click apply.
• Restart IIS.

The subdomains you listed in the code should now work with all domains and redirect to the relevant pages icon_smile.gif

If customers create subdomains, they will override the settings here (which is a good thing in most setups).

Hope you find this useful icon_cool.gif
BeHosts
[php]/* chris@onestopwebhosting.com */
/*
$redirects format:
"friendlyname" => array(
name => "subdomain",
url => "http://sd.example.com",
framed => true),

friendlyname = Anything.
name = The subdomain you want redirected.
url = The url it should go to.
framed = true / flase
If true it will load the url in a frameset
(keeping the address in the address bar),
if false it will just redirect them.

$missingtext = The html that is displayed if a subdomain
is entered that is not in the list.

*/

$redirects = array(
"webmail" => array(
name => "webmail",
url => "http://webmail.onestopwebhosting.com",
framed => true),
"mail" => array(
name => "mail",
url => "http://webmail.onestopwebhosting.com",
framed => true),
"helm" => array(
name => "cp",
url => "http://cp.onestopwebhosting.com",
framed => false)
);

$missingtext = "

There is no site here.

";

/* ignore below */

$host = strtok($_SERVER['HTTP_HOST'], '.');

foreach ($redirects as $redirect) {
strchr($redirect['name'], '.');
}

foreach($redirects as $redirect) {
if (strcasecmp($redirect['name'], $host) == 0) {
if (!$redirect['framed']) {
$url = sprintf("Location: %s", $redirect['url']);
header($url);
exit(0);
} else {
$url = $redirect['url'];
$useframes = $redirect['framed'];
}
}
}

if ($useframes && !empty($url)) { ?>


<?=$host ?>









Missing Subdomain!





[/php]

Updated code.

There are two new options:
• framed: If set to true, the url will be loaded in a frame so the subdomain URL will still be in the address bar.
• missingtext: HTML to display if the subdomain entered is an invalid one.

icon_cool.gif
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.