The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Subdomains vs Sub directories

Discussion in 'General Discussion' started by sqwale, Feb 15, 2012.

  1. sqwale

    sqwale Registered

    Joined:
    Jan 19, 2012
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Website Owner
    I'm a newbie with the whole internet however I have a background in programming. I have written a web application but I would like to add a feature that allows registered users to have some form of a sub-domain. I have come across some forums that enable you to create a sub-domain with PHP and CPannals API's like;
    username.mywebsite.com.
    So when my user signs up they get this sub-domain.

    However I would rather it would mimic facebook. So when a user joins they get something like mywebsite.com/username. I know at first it seems as simple as just adding a directory. But I suspect there is a more formal and neat way of doing this without riddling my publi_html folder with hundreds if not thousands of username subdirectories.
     
  2. cPanelTristan

    cPanelTristan Quality Assurance Analyst
    Staff Member

    Joined:
    Oct 2, 2010
    Messages:
    7,623
    Likes Received:
    21
    Trophy Points:
    38
    Location:
    somewhere over the rainbow
    cPanel Access Level:
    Root Administrator
    Since a subdomain would also be accessible using maindomain.com/subdomainfolder, then I'm uncertain why you wouldn't go ahead and let the subdomain be created. This would allow people to access using both the subdomain and maindomain.com/subdomainfolder which could be the same as the username. Providing people with two ways to access the same content isn't a bad option at all. You don't have to provide the subdomain to the users if you don't want to and the maindomain.com/subdomainfolder would be a valid path to mention in any account generation email you mail out to those users.

    One thing I'm uncertain about is the comment on not riddling public_html with numerous username subdirectories. No matter how you look at it, you'll be creating a large number of subdirectories somewhere. If you don't want them in public_html, where else did you want them to be created?
     
  3. sqwale

    sqwale Registered

    Joined:
    Jan 19, 2012
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Website Owner
    Thank you so much for your response, like I said I'm not that competent with cPanel. I know the folders would have to go somewhere I just don't want them in the public_html so i can clearly know what folders are user folders. Is there someway i can have a user subfolder with all the users folders. However i don't have to add the user to my url. E.G.
    Mywebsite.com/users/userX could be found by just typing in Mywebsite.com/userX. I.e. is there some code i can add to my .htaccess that does this?

    if((subfoldername!=A) ||(subfoldername!=B)|| (subfoldername!=C)){
    redirect_to(Mywebsite.com/users/subfoldername)
    }

    A, B and C are sub folders within my pubic_html folder which can be accessed. Hence if my sub folder name is either of the above you will be redirected there as per normal operation.
    But if its not either of the above add the users to the url and add the sub foldername to the url.

    or anyother methods that will result in a similar effect.
     
    #3 sqwale, Feb 27, 2012
    Last edited: Feb 27, 2012
  4. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    30,854
    Likes Received:
    676
    Trophy Points:
    113
    cPanel Access Level:
    Root Administrator
    Hello :)

    You can choose the directory path for the subdomains when you create them. If you choose, you can enter a path outside of the public_html directory. EX:

    Code:
    /testsubdomain
    This will configure the path for the subdomain to "/home/username/testsubdomain". The subdomain will still be accessible via:

    Code:
    http://testsubdomain.domain.com
    If you then want the content also accessible via "domain.com/testsubdomain", you could create a symbolic link. EX:

    Code:
    # ln -s /home/username/testsubdomain /home/username/public_html/testsubdomain
    Thank you.
     
Loading...

Share This Page