skip to Main Content

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)

4

Answers


  1. WordPress doesn’t create subdomain, it even can’t create it since this is a part of apaches virtual host configuration files.

    The only way to make subdomain is to create another virtual host record, add it to the DNS record, but that takes 24 hours to refresh DNS servers. Plesk and other control panels can manage that, but WordPress can’t since it’s only PHP script which probably doesn’t even have permissions to do that kind of stuff. Besides, you don’t specify where you configuration file is, so WordPress can’t know where virtual host are 🙂

    Please tell us more about that WordPress subdomains, where you create them etc.

    Login or Signup to reply.
  2. 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.

    Login or Signup to reply.
  3. 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.

    Login or Signup to reply.
  4. Also please note that you can via. Apache set it up so it uses a regular expression on the incomming hostname and through this set document root to be something like:

    /var/www/topleveldomain.com/subdomain/wwwroot
    

    This can give the illusion that there’s been change in config files and all that black magic to allow mysubdomain.topleveldomain.com to become a new subdomain just by creating a folder in the right place.

    Also note, this goes with the star aliasing in the DNS record.

    However, I doubt that’s how wordpress does it and the way Paul Dixon mentions is probably more likely.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search