Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does wordpress.com and other similar services create a subdomain instantly, that is instantly available?

i know almost anything about sub-domains and dns records. i have heard about them and i know just the basics.

Actually, on my server, i do create the subdomain under plesk and then contact my hosting to create the right dns. and in 1-2 days the subdomain is reachable from everywhere (plesk can manage dns automatically, i know, but becose i dont know how does dns exactly works, i prefer to let my hoster handle them)

But.. when you do register on wordpress.com, posterous.com, etc, they create a subdomain like http://yourname.service_name.com that is ready in few seconds.. how?

I know this could be an question hardly to response because my ignorance i dont know how to formulate the question better -.-

Oh, if it can help, my environment must be linux (debian actually)

like image 747
Strae Avatar asked Jul 21 '09 10:07

Strae


People also ask

How do I create a subdomain in WordPress?

To do this in cPanel, look for the Subdomains tool in the Domains section: On the next screen, enter your desired subdomain in the Subdomain box and also select the parent domain via the Domain drop-down. There's no need to add a dot after the subdomain – just enter the text you want to use.

How is a subdomain created?

Creating a SubdomainEnter the desired subdomain. Choose one of your Domain Names from the drop-down list. Enter the Document Root (this is the folder that contains the website you want to show). We recommend that you use the same name for this folder as your subdomain.

How long does it take for subdomain to appear?

After creating a subdomain via your DNS zone, it'll take up to 24 hours for the changes to take effect and the subdomain to work.


2 Answers

Most people achieve this by using a Wildcard DNS Record, this gives the appearence of creating subdomains instantly.


Once you've got a wildcard DNS setup like this:

 *.example.com          A     77.75.105.197

You need to tell Apache you want all sub domains to be caught by a virtual host, you can do this with ServerAlias:

ServerAlias *.example.com

In PHP you can then look at $_SERVER["SERVER_NAME"] to figure out what subdomain has been used to access the virtual host, you can then have subdomain specific code/content.

like image 77
Luke Antins Avatar answered Oct 21 '22 13:10

Luke Antins


Here's the way pastebin.com does this:

  • wildcard DNS record points all subdomains at the webserver IP
  • apache will send all requests for "unknown" domains to the first virtual host - you make the code on that host capable of doing something interesting with the domain name (in PHP, this is presented as $_SERVER['HTTP_HOST']

That way, no DNS or Apache re-configuration is required.

like image 40
Paul Dixon Avatar answered Oct 21 '22 15:10

Paul Dixon