Click to See Complete Forum and Search --> : How to create a Sub-Domain


atortega
08-19-2005, 03:31 AM
I had a domain name called www.sugbo-online.com

Now, all users registed to my web-site has a folder named corresponding to their account name.

I want this users to display their account page someting like this: www.JOHN.sugbo-online.com and not like this www.sugbo-online.com/JOHN

I understand that doing that way, we should create a sub-domain name for each user. I don't want to use the control panel of my hosting service to create a subdomain for every user of my site. I want this done automatically upon their registration.

Is there any available script for this?

Please help....

zingmatter
08-19-2005, 06:07 AM
a subdomain would be john.sugbo-online.com (no www). Interested to hear it's done. Found this online:
http://aspn.activestate.com/ASPN/Mail/Message/php-db/2053757

bokeh
08-19-2005, 08:50 AM
Yes there is a PHP solution and if you wait for a few minutes I will post it. What you are looking for is a psuedo sub domain.

By the way, there is no reason why a sub-domain couldn't contain the 'www' prefix, it is just unusual.

bokeh
08-19-2005, 09:23 AM
You need to set up a wildcard DNS entry (*.domain.com) and a wild card virtual server alias ( ServerAlias domain.com *.domain.com). This will redirect all wildcard requests into your default directory. Now all you need to do is sort them. I would use something like the following right at the start of your root directory index.php file:


<?php

$host = $_SERVER['HTTP_HOST'];
$domain = 'domain.com'; //alter to suit
if(($host != $domain or $host != 'www'.$domain) and list($user_dir) = spliti('\.', str_replace('www.', '', $host)) and is_dir($user_dir)){
header('Location: '.$host.'/'.$user_dir);
exit();
}

?>

Now all you need to do is when a new user signs up just create a directory inside your root directory which is the same as the username.

atortega
08-19-2005, 10:48 PM
Thanks bokeh. I will try that one now.

k0r54
08-20-2005, 04:30 AM
wow, lol its a little simpler than i thought to create a sub domain, i think ill keep this code as i will probably some day need it lol :)

Thanks
Adam