Subdomain Creation

Discussion in 'PHP' started by MrLeN, Jul 19, 2011.

  1. #1
    I have created a members area on a website where members can create a personal web page for themselves. The page winds up being at:

    mywebsite.com/user

    So far so good (all working nicely)..

    However, I want that user to be able to acces the page with a subdomain, because it looks a lot nicer. ie:

    user.mywebsite.com

    What is the easiest way I can go about this?
     
    MrLeN, Jul 19, 2011 IP
  2. xkaser101

    xkaser101 Peon

    Messages:
    84
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Yes please anyone got an answer I was wondering how is that possible ? :p
     
    xkaser101, Jul 19, 2011 IP
  3. MrLeN

    MrLeN Well-Known Member

    Messages:
    406
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    120
    #3
    Don't hold your breath for a solution. I've been searching Google for:

    virtual subdomains
    create subdomain mod rewrite
    htaccess subdomains
    wildcard subdomains
    craete subdomain for user folder
    subdomain tutorial
    virtual subdomain tutorial
    (and about 5 dozen other variations)..

    ..and I've looked several pages deep under each search, and all I can find is either answers that don't really answer (ie: "yeah, just use virtual subdomains"), or answers that are similar but not really what I want (or are the oppositie of what I want).

    Apparently, if you want a server to display the contents of:

    website.com/user

    under:

    user.website.com

    You have to find the wizard of oz or something.

    As far as I can see, no one on the Internet knows how to do it.

    Or, there's some secret society that have employed tens of thousands of people to erase the knowledge from the internet, in case Darth Vader find out or something.
     
    MrLeN, Jul 19, 2011 IP
  4. CrostE

    CrostE Peon

    Messages:
    30
    Likes Received:
    1
    Best Answers:
    1
    Trophy Points:
    0
    #4
    Try looking here
     
    CrostE, Jul 20, 2011 IP
  5. MrLeN

    MrLeN Well-Known Member

    Messages:
    406
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    120
    #5
    I have already seen that page and used that script, and it works, but it still doesn't help me.

    I need:

    jack.mywebsite.com

    to display the contents of:

    mywebsite.com/jack
     
    MrLeN, Jul 20, 2011 IP
  6. jazzcho

    jazzcho Peon

    Messages:
    326
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #6
    It's called mod_rewrite, assuming you use Apache as a web server.

    It 's the secret society.
     
    jazzcho, Jul 20, 2011 IP
  7. Abhishek Kundu

    Abhishek Kundu Active Member

    Messages:
    133
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    58
    #7
    hi MrLen,

    there are several methods that you can take to create sub-domains for your website.

    METHOD 1 (ASSUMING THAT YOU DON'T HAVE ACCESS TO THE httpd.conf FILE)
    1. Open the .htaccess file
    2. Insert the code listed below
      
      #Grab the subdomain from the domain
      RewriteCond %{HTTP_HOST} ^([^.]+).hm2k.org$
      #Make sure the subdomain is not www or example
      RewriteCond %{1} !^(www|example)$
      #Check if the directory actually exists before we go there
      RewriteCond /home/hm2k/public_html/%1 -d
      #This stops it from looping
      RewriteCond %{REQUEST_FILENAME} !^/home/hm2k/public_html/
      #Finally, this is the actual rewrite
      RewriteRule (.*) /home/hm2k/public_html/%1/$1 [Last]
      
      Code (markup):
    3. save the .htaccess file
    METHOD 2 (ASSUMING YOU CAN ACCESS CPanel)
    1. if you have cpanel then you can ask your users to send a request and you will crate the sub-domain manually via cpanel.

    i hope this comes in useful to you and others who need a similar solution. :)
     
    Abhishek Kundu, Jul 21, 2011 IP
  8. xkaser101

    xkaser101 Peon

    Messages:
    84
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    hehehe good luck =)
     
    xkaser101, Jul 23, 2011 IP
  9. ezprint2008

    ezprint2008 Well-Known Member

    Messages:
    611
    Likes Received:
    15
    Best Answers:
    2
    Trophy Points:
    140
    Digital Goods:
    1
    #9
    this is simple .
    On your webhost add a subdomain and the folder (treated as a completely new website on your host) instead of giving it a domain name like www.newsite.com
    you just give it the domain of user.www.mywebsite.com

    This could be the home page for that site which they can log into from there. or have user.mywebsite.com/user1029

    But obviously you're only wanting the user.mywebsite.com
    A fix in 5 seconds at your webhosts TOOLS and domains settings.
    They should have something already set up for SUBDOMAINs (I know places like Lunarpages.com has this standard in their tools and Ive nested 1over 100 sites inside of a top level before. you should even be able to set up emails etc for your subdomain by using their tools.
    A redirect as others are telling you is useless ..they're only giving you options to have the ADDRESS BAR display changed ..but it doesnt literally create a directory/site for users

    At lunar pages when you create a subdomain you can give it its own domain name , example www.completely_new_site.com OR if youre nopt purchasing a new domain name, you just give it a subdomain name off of your already existing site. (exactly what you're asking) products.mysite.com , stuff.mysite.com

    If your host doesnt allow subdomains, they suck. on lunarpages you can create as many as you want .
     
    ezprint2008, Jul 25, 2011 IP