Wildcard Subdomains 101

Every request to MyStageBio - the bare domain, any performer's subdomain, a verified custom domain, even the temporary cPanel URL before DNS was live - hits the exact same PHP file. What renders depends entirely on one thing: the Host header.

One front controller, four cases

The whole router boils down to reading the hostname and branching. If it's {something}.mystagebio.com, look up that performer's tenant row and render their page - or a 404 if the subdomain doesn't exist, or a "demo expired" page if their account access has lapsed. If it's the bare domain or www, render the marketing landing page. If it's neither, check whether it matches a verified custom domain and render that tenant's page if so. Anything left over falls back to the landing page too, which covers the temporary host before DNS was pointed anywhere real.

There's a small pre-launch convenience baked in: before mystagebio.com's DNS was live, a ?site=subdomain query parameter let me preview any tenant's page on the temporary host. That override only works when the request isn't already on the real domain - once it is, the override is ignored outright, so it can't later be used to spoof a tenant by appending a query string to someone else's real subdomain.

The canonical-host problem

Once a performer verifies a custom domain, their page becomes reachable at two different URLs - their subdomain and their custom domain - and both render byte-for-byte the same content. Left alone, that's textbook duplicate content as far as Google is concerned. The fix is a canonical host function: whichever URL a request arrives on, the page declares one of the two (the custom domain, once it exists) as the canonical version via rel="canonical", so search engines know which one to actually index.

Don't miss a post

Get new posts by email

An email whenever something new goes up on the blog. No spam, unsubscribe anytime.

Building something of your own?

If you need a custom site or web application built the same hands-on way, let's talk.

Get in touch