auto generating subdomain

Discussion in 'PHP' started by cris02, Sep 2, 2010.

  1. #1
    Hi,

    I would like to ask regarding creating a subdomain automatically after signup on a site.
    example after registration i have my personal url link like http://myusername.mywebsite.com then when i type that url it will automatically redirect in login form a mywebsite.com. I know it can be done in htaccess but i can't figure it out. Please help thanks.
     
    cris02, Sep 2, 2010 IP
  2. ndevendra

    ndevendra Member

    Messages:
    6
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    36
    #2
    First things is that you need to have wild card subdomains enabled in the server, and a CNAME record * pointing to the root of the site or somewhere on the site.

    After that you may just take the myusername part from the HTTP_HOST variable using some algorithm to get the subdomain http://myusername.mywebsite.com or simply write a rule to get the subdomain name in a variable.

    With subdomain pointing to the same script file, we can program it using conditions for the main domain or the subdomain.
     
    ndevendra, Sep 2, 2010 IP
  3. cris02

    cris02 Member

    Messages:
    55
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #3
    thanks for the reply, i have created a subdomain on my cpanel something *.mydomain.com , now any subdomain redirect to the site, how can i filter that subdomain and redirect to url something like http://mydomain.com/index.php?do=login. Thanks
     
    cris02, Sep 2, 2010 IP
  4. ndevendra

    ndevendra Member

    Messages:
    6
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    36
    #4
    You can do that using simple php. Create a php function to get the subdomain name from subdomain.domain.com. If the subdomain is empty or www, do not redirect, else do the redirect.
     
    ndevendra, Sep 2, 2010 IP