skuvnar — 2011-08-03T02:11:40-04:00 — #1
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!
dan_grossman — 2011-08-03T05:43:10-04:00 — #2
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.
skuvnar — 2011-08-03T06:55:57-04:00 — #3
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):
// 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?
chriswiegman — 2011-08-03T14:49:05-04:00 — #4
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.
dan_grossman — 2011-08-03T15:02:00-04:00 — #5
Not sure how helpful that'll be...
$domain = $_SERVER['HTTP_HOST'];
mysql_connect('localhost', 'username', 'password');
$result = mysql_query("SELECT id FROM users WHERE domain = '$domain'");
$row = mysql_fetch_assoc($result);
skuvnar — 2011-08-03T18:29:56-04:00 — #6
Many thanks for the help guys. I understand how it works now.
Thanks again. Regards.
mittineague — 2014-10-02T20:15:40-04:00 — #7
This topic is now archived. It is frozen and cannot be changed in any way.