SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Member
    Join Date
    Apr 2009
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    implementing custom domains

    Hi guys,

    Just wondering how sites like tumblr or weebly are able to implement custom domains. For example when you first sign up you get a sub domain like "user01.tumblr.com". But they allow you the option of changing that to your own domain, provided that you supply the nameservers.

    I just want to know what is going on behind the scenes...

    (PS: sorry for a very basic question, I am fairly new to server administration and still trying to get my head around how DNS works).

    Any help would be greatly appreciated. Many thanks!

  2. #2
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,580
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    You point the DNS record for your domain (A or CNAME) to tumblr's servers. No different than pointing it at your own server.

    Their web server gets the HTTP requests the same as if it was their domain.

    All HTTP requests are pointed to the same document root; no virtual hosts or anything else domain specific.

    Their code looks up what user has registered that hostname and shows their site.

    Tumblr itself doesn't have to do anything to support custom domains except store what domain is associated with what user in their database.

  3. #3
    SitePoint Member
    Join Date
    Apr 2009
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks Dan for the help. That made it clearer for me. So just to confirm, the code that tumblr executes, would look something along the lines of (pseudo code):

    Code:
    // get the requested url (eg the custom domain)
    
    // find in the database the user with the custom domain
    
    // serve the page that is linked with that user
    Would this be right or am I totally off the mark. Also could you direct me to any code samples that demonstrates this?

    Thanks again.

  4. #4
    SitePoint Zealot ChrisWiegman's Avatar
    Join Date
    Sep 2010
    Location
    Austin, Texas, United States
    Posts
    177
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Skuvar, take a look at how DNS works. I think that will answer most of your questions. As to the code, while I don't have an actual example I can tell you it is easily done just by mapping the user's domain to the site in the database. Once that is done you have numerous choices on how to implement the redirection itself based on the application your using.

  5. #5
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,580
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by skuvnar View Post
    Would this be right or am I totally off the mark. Also could you direct me to any code samples that demonstrates this?
    Not sure how helpful that'll be...

    PHP Code:
    $domain $_SERVER['HTTP_HOST'];

    mysql_connect('localhost''username''password');
    mysql_select_db('users');
    $result mysql_query("SELECT id FROM users WHERE domain = '$domain'");
    $row mysql_fetch_assoc($result);

    show_website_of_user($row['id']); 

  6. #6
    SitePoint Member
    Join Date
    Apr 2009
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Many thanks for the help guys. I understand how it works now.

    Thanks again. Regards.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •