Setting up subdomains dynamically, php-code wise?

Discussion in 'Site & Server Administration' started by fatabbot, Dec 2, 2006.

  1. #1
    Hello,


    Is there a possible way to set up subdomains for a domain automatically; in programming code for example?

    Like when a user registers on a site, he automatically gets a subdomain assigned.

    Regards,


    Fat Abbot
     
    fatabbot, Dec 2, 2006 IP
  2. Mystique

    Mystique Well-Known Member

    Messages:
    2,579
    Likes Received:
    94
    Best Answers:
    2
    Trophy Points:
    195
    #2
    you can make virtual subdomains using .htaccess.

    I have not the information at hand, but google it ;)
     
    Mystique, Dec 2, 2006 IP
  3. agnivo007

    agnivo007 Peon

    Messages:
    4,290
    Likes Received:
    289
    Best Answers:
    0
    Trophy Points:
    0
    #3
    thats called wildcarded subdomains. for eg - aaa.bbb.com maps to bbb.com/aaa etc...
     
    agnivo007, Dec 2, 2006 IP
  4. thuonghieu

    thuonghieu Peon

    Messages:
    105
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    thuonghieu, Dec 3, 2006 IP
  5. fatabbot

    fatabbot Well-Known Member

    Messages:
    559
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    138
    #5
    fatabbot, Dec 3, 2006 IP
  6. agnivo007

    agnivo007 Peon

    Messages:
    4,290
    Likes Received:
    289
    Best Answers:
    0
    Trophy Points:
    0
    #6
    wildcarded subdomains enabled and .htaccess (mod_rewite) redirect to the actual url of profile
     
    agnivo007, Dec 4, 2006 IP
  7. fatabbot

    fatabbot Well-Known Member

    Messages:
    559
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    138
    #7
    I need to add a line in .htaccess manually each time someone registers ?
     
    fatabbot, Dec 4, 2006 IP
  8. Scolls

    Scolls Guest

    Messages:
    70
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #8
    I do this, but on a Windows server with Apache 2.x.x. The big trick is this:
    in your httpd.conf file you need your first virtualhost to contain:

    VirtualDocumentRoot "dir_path_to_where_you_want_the_subdomains_to_be\%1"

    This requires the vhost_alias_module (mod_vhost_alias.so) to be loaded in your DSO support section of httpd.conf.

    Now all you have to do everytime you want to grant somebody a subdomain is just create the subdirectory with mkdir(). (and, of course, record his details in your DB for your own reference.)

    I did battle my butt off to get the thing to work the first time, but there is quite a lot of documentation at apache about mod vhost_alias.
    If I remember correctly, the biggest struggle was because I wasn't putting that vhost with the virtualdocumentroot first. I also forget now whether I needed followsymlinks for the directory section pertaining to the domain.

    "dir_path_to_where_you_want_the_subdomains_to_be\%1" really just tells apache to take the first part of the server string and stick it on the end of the root domain, eg

    subdomain1.mysite.com becomes mysite.com/subdomain1

    Of course, you'd want to regulate the signup process to include a check on what subdomains have already been dished out, as well as whichever you've used for yourself.

    Works like a bomb, and I don't have to do anything at all (my favourite activity! :D). If you have any problems, just give me a shout. :cool:
     
    Scolls, Dec 5, 2006 IP