domain_sxc_49702_3823-300x225 I’ve worked on several sites lately where my client wanted each of their website members to have their own subdomain.

Typically, when you set up a subdomain it takes up to 72 hours for the DNS to propagate and start working.

I’ve been trying to find a way to allow subdomains to start working right away somehow in my code.

Through trial and error I figured it out. If you are using cpanel, you can click on the subdomain icon or link and add a wildcard subdomain.

The wildcard is just as asterisk (*). It should look something like this:


The Document Root should be set to wherever you want to handle the incoming request. In this case, I have it set to my public_html folder where I will then dispatch the request to where I want it to go based on the subdomain typed in the address bar.

Now, any subdomain that is typed in the address bar will come to my site unless I have an actual subdomain set up in the DNS – those are handled first by the DNS. For instance, if I don’t have any regular subdomains set up for my website, then with the wildcard sudomain setup regardless of what I type in for the subdomain, they will all be directed to my home page:

Since I don’t have any of these setup as actual subdomains, the wildcard handles these and sends the request to my home page at

If, however, you use one of these:

they will go to the correct location. The DNS intercepts since I have them set up as true subdomains.

I can find out the subdomain used by the wildcard to reach my script by looking at $_SERVER[‘HTTP_HOST’] or $_SERVER[‘SERVER_NAME’] inside my script.

Using the wildcard subdomain keeps me from making my members wait until their subdomain has propagated. I can just handle the dispatching in my code for the domain.

Problem solved.

2 thoughts on “Building Dynamic Subdomains”

  1. 🙂 the wildcard tip is great, especially if you’re worki wingth wordpress mu/buddypress or any other script that dynamically creates sites on the fly – I’ve been using this since before cpanel supported it properly – editing it on the server was *so* much more complicated 😉

Leave a Comment

Your email address will not be published. Required fields are marked *