View Full Version : How to set a script to create a subdomain for each folder I create?
Adrian
12-27-2007, 05:30 PM
Hello all
I am trying to have a script set up so everytime I create a folder on my hosting package it automatically creates a subdomain for it. for example if I create a folder called "new" under "mydomain.com" and the address for it is www.mydomain.com/new i want to have a script setup so it creates www.new.mydomain.com and point it to the folder I created.
I am really lost on how to this, from what I have read on different forums I will have to create a catch all record in my DNS zone then use mod_rewrite but I am not sure how to do that.
any help from you would be greaty appreciated.
tbh i dont think there is a script for this you just have to do it manually
You can do it this way:
Have your dns server set up to point *.yourdomain.com to your host name. so *.yourdomain.com points to www.yourdomain.com. Then in the root of the public html dir make an index.php that based on the "Host: " header sends it to the correct directory.
eg.
I log on to www.gallery.yourhost.com it points to www.yourhost.com.
code of index.php in ~/public_html/:
<?php
$hostname = $_SERVER["HTTP_HOST"];
if($hostname == "www.profile.yourhost.com" || $hostname == "profile.yourhost.com") header('Location: http://www.yourhost.com/profile');
if ($hostname == "www.gallery.yourhost.com" || $hostname == "gallery.yourhost.com") header ('Location: http://www.yourhost.com/gallery');
else {
Normal cont. of ~/public_html/index.php
}
?>
That make any sense at all? if not, email me :)
edit:
This would be the predefined way. You can do it by having the script check if the folder exist instead. What you want to do is possible, anyone with basic to intermed php skills can do this. Contact me if you're interested. ( dont know if im gonna be staying on this site.)
Adrian
01-01-2008, 07:49 PM
Thanks for the answer but my problem is I cannot set *.mydomain.com , I get error: Wild card not allowed. I contacted HostMonster support to see if they can edit my DNS zone but they are not going to do it.
I gave up on the idea... thanks for your response anyways....
Did they give any reason? I mean, i dont see why they cant do that.
This works for me
<?php
if (isset($create)) {
$login = "cpaneluser";
$pass = "cpanelpassword";
$domain = "domain.com";
$output = fopen ("http://$login:$pass@www.$domain:2082/frontend/hostmonster/subdomain/doadddomain.html?domain=$subdomain&rootdomain=$domain&dir=public_html/$subdomain", "r");
$output = fopen ("http://$login:$pass@www.$domain:2082/frontend/hostmonster/ftp/doaddftp.html?login=$subdomain&password=$ftppass&homedir=public_html/$subdomain"a=10", "r");
print ("Subdomain Created.<br>\n");
print ("You can now access it at <a href=\"http://$subdomain.$domain\">http://$subdomain.$domain</a><br>\n");
print ("You also have ftp access. Log in at <a href=\"ftp://ftp.$domain\">ftp://ftp.$domain</a> with the username $subdomain@$domain and the password $ftppass\n");
} else {
?>
<html>
<head>
<title>Automatic Subdomain Creator</title>
</head>
<body bgcolor="#FFFFFF" text="#000000">
<form method="post" action="<?php print($_SERVER['PHP_SELF']); ?>">
Subdomain: <input name="subdomain" type="text"><br>
Password: <input name="ftppass" type="password"><br>
<input name="create" type=submit value="Create">
</form>
<?php
}
?>
Haha, of course... REALLY nice :D
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.