How to create Sub Domains using a script
Moderator: General Moderators
-
ibizconsultants
- Forum Commoner
- Posts: 35
- Joined: Tue Sep 07, 2004 12:07 pm
How to create Sub Domains using a script
Hi all,
I have a requirement where in each time a user registers on the system, I need to create and assign a subdomain for him.
The server is not a shared server and is dedicated to the project.
Can anyone guide me on the best way to approach this situation.
Thanks in advance.
iBizConsultants
I have a requirement where in each time a user registers on the system, I need to create and assign a subdomain for him.
The server is not a shared server and is dedicated to the project.
Can anyone guide me on the best way to approach this situation.
Thanks in advance.
iBizConsultants
-
ibizconsultants
- Forum Commoner
- Posts: 35
- Joined: Tue Sep 07, 2004 12:07 pm
Thanks for the reply.
2. The script would just create the subdomain on the server.
3. I would not delete the subdomain, as the users are never deleted from the system.
Can anyone help me with how to do this.
Thanks again
1. I really dont know the procedure to create a subdomain. If you are asking about the business rule, then anyone who signs up gets a subdomain.astions wrote:1. What is the procedure for creating a subdomain on your server?
2. How could you accomplish this with a script? What would the script need to do?
3. What if you need to delete a subdomain?
2. The script would just create the subdomain on the server.
3. I would not delete the subdomain, as the users are never deleted from the system.
Can anyone help me with how to do this.
Thanks again
- AKA Panama Jack
- Forum Regular
- Posts: 878
- Joined: Mon Nov 14, 2005 4:21 pm
Here is one way... Actually we use it at http://www.aatraders.com for all of the personal blogs at that site. IE: http://panamajack.aatraders.com
First, your DNS definitions for your domain name have to include a *.aatraders.com wildcard A record, so that all subdomains are mapped to your one server's IP address. 'panamajack' is just one subdomain, 'tarnus' is another one. You need the * to catch them all.
Then, in your web server's configurations file httpd.conf, within your virtual host definition for aatraders.com you have to specify a * wildcard alias, so that every possible subdomained host name points to the same document root of aatraders.com.
Now you are ready to catch the subdomains within PHP, $subdomain = explode(".",$_SERVER["HTTP_HOST"]); and do whatever you want with it.
Then depending upon what is in the $subdomain variable I include the appropriate php file. If there is a subdomain I load the blog code. If there isn't a subdomain then I load the main page.
First, your DNS definitions for your domain name have to include a *.aatraders.com wildcard A record, so that all subdomains are mapped to your one server's IP address. 'panamajack' is just one subdomain, 'tarnus' is another one. You need the * to catch them all.
Then, in your web server's configurations file httpd.conf, within your virtual host definition for aatraders.com you have to specify a * wildcard alias, so that every possible subdomained host name points to the same document root of aatraders.com.
Code: Select all
<VirtualHost *:80>
DocumentRoot /***/***/***
ServerAdmin webmaster@aatraders.com
ServerName www.aatraders.com
serveralias profiles.aatraders.com aatraders.com *.aatraders.com
ErrorLog /***/***/aatradersweb.error_log
CustomLog /***/***/aatradersweb.access_log combined
ScriptAlias /cgi-bin/ /***/cgi-bin/
</VirtualHost>Code: Select all
if(strtolower($_SERVER["HTTP_HOST"]) != "www.aatraders.com" && strtolower($_SERVER["HTTP_HOST"]) != "aatraders.com")
{
$domain = explode(".", $_SERVER["HTTP_HOST"]);
$subdomain = $domain[0];
}
else
{
$subdomain = '';
}
Last edited by AKA Panama Jack on Wed Jun 21, 2006 3:29 pm, edited 1 time in total.
-
ibizconsultants
- Forum Commoner
- Posts: 35
- Joined: Tue Sep 07, 2004 12:07 pm
- AKA Panama Jack
- Forum Regular
- Posts: 878
- Joined: Mon Nov 14, 2005 4:21 pm
or with mod_vhost_alias: http://httpd.apache.org/docs/2.0/en/vhosts/mass.html
This method is most suited for services like hosting providers... if everything you need is to replace urls like 'site.com/script.php?user=username' with 'username.site.com' then I'd suggest to go either with mod_rewrite route or APJ suggestion.
This method is most suited for services like hosting providers... if everything you need is to replace urls like 'site.com/script.php?user=username' with 'username.site.com' then I'd suggest to go either with mod_rewrite route or APJ suggestion.
http://httpd.apache.org/docs/2.0/en/vho ... le.rewriteCan you please guide me on how to do this with mod_rewrite.... wont all the urls be re-written if i use a general rule. Can you please help me understand in more details... am new to this completely. Sorry for the trouble
- neel_basu
- Forum Contributor
- Posts: 454
- Joined: Wed Dec 06, 2006 9:33 am
- Location: Picnic Garden, Kolkata, India
Would I Save It As .htaccess Under htdocs FolderWeirdan wrote:http://httpd.apache.org/docs/2.0/en/vho ... le.rewriteCan you please guide me on how to do this with mod_rewrite.... wont all the urls be re-written if i use a general rule. Can you please help me understand in more details... am new to this completely. Sorry for the trouble