How to create subdomain for each member

Discussion in 'Programming' started by dshah, Aug 8, 2006.

  1. #1
    I want to have subdomain created for each member like username.domain.com upon registration.

    Something like what happens with blogspot (blogger). Is it subdomain or just redirect in .htaccess?

    How to do this?

    Thanks
    dshah
     
    dshah, Aug 8, 2006 IP
  2. SaN-DeeP

    SaN-DeeP Well-Known Member

    Messages:
    590
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    140
    #2
    This feature requires that wildcard domains are enabled for our domain so that *.domain.com is resolved to the same IP address, and to the same directory that your main domain points to. or in other words, there is no need to create the subdomains before they are used because when using wildcard subdomains, all possible host names will be resolved to the same address (and directory!)

    You need to configure Apache using wildcard domains, check this 2 excellent articles for same here:
    http://steinsoft.net/index.php?site=Programming/Articles/apachewildcarddomain
    http://photomatt.net/2003/10/10/wildcard-dns-and-sub-domains/
     
    SaN-DeeP, Aug 8, 2006 IP
  3. Reuben

    Reuben Peon

    Messages:
    162
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #3
    you could use mod_rewrite for this.
     
    Reuben, Aug 9, 2006 IP
  4. dshah

    dshah Well-Known Member

    Messages:
    1,840
    Likes Received:
    69
    Best Answers:
    0
    Trophy Points:
    115
    #4
    Could you give specific detailed instructions, I am kinda new to this.
     
    dshah, Aug 9, 2006 IP
  5. Mattox

    Mattox Guest

    Messages:
    141
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #5
    What language are you going to be programming in mate?
     
    Mattox, Aug 9, 2006 IP
  6. dshah

    dshah Well-Known Member

    Messages:
    1,840
    Likes Received:
    69
    Best Answers:
    0
    Trophy Points:
    115
    #6
    PHP. I thought it would be just in .htaccess, but looks I was thinking wrong.

    Thanks for help!
     
    dshah, Aug 9, 2006 IP
  7. ajscottsr

    ajscottsr Peon

    Messages:
    388
    Likes Received:
    28
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Let's assume you already have the wildcard DNS working, here is a mod_rewrite example to capture the subdomain and use it realistically in the program.

    In the above example, the first line sets the subdomain into %1 which can then be used in the second line.

    That means that:

    http://me.yourdomain.com

    Would automatically get converted to:

    http://www.youdomain.com/program.php?user=me

    There are other ways to accomplish this as well.

    You would have environment variables which have the host name me.yourdomain.com in them. You could use PHP to split on the period and take the first value coming out and set that as the username. That would allow you to do it internal to the script and WITHOUT the need for mod_rewrite.

    Hope this helps.
     
    ajscottsr, Aug 9, 2006 IP
  8. sacx13

    sacx13 Active Member

    Messages:
    438
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    58
    #8
    sacx13, Aug 11, 2006 IP