Faux sub-domain


This is my first time dealing with sub-domains, and I was hoping for help with an overview of the steps that I’d need to achieve my objective. For my website, I’d like to have sub-domains for each of the customers, so that they can type in URLs such as:


However, they’ll “act” as if they went to:


In other words, the “cool_customer_1” is something cosmetic to add personalization to the site.

Currently I’m routing everything through my index.php file via .htaccess (it’s a custom MVC app that I wrote):

RewriteRule ^(.+)$ index.php?url=$1 [QSA,L]

What I’m unclear about is what needs to happen so that I can add “cool_customer_1” to my_domain so that the same re-write applies. Can I do this all programatically? Do I need to change something in my account which has my Domain (ie GoDaddy)? Do I need to change something in my account that hosts my actual site?

Note that “cool_customer_1” will be chosen by my users via a form so that an automated process would be how I would need to approach this.

Hi Kraut,

A subdomain is another server so, although some hosts will allow “wildcard” subdomains, from my limited knowledge of these strange beasts, most don’t. Therefore, if you need to use a subdomain, you’ll need to add it to your domain (a cPanel task). When you add a subdomain, though, because of the way you want the main domain to handle the request, be sure to redirect TO your main domain’s DocumentRoot (the typical setup is for the subdomain to be in a subdirectory of the main domain so that it bypasses - and cannot access - the main domain’s DocumentRoot.

The second thing you need to be concerned with is GoDaddy. From my years as a TL here, I heard from too many members that, while GoDaddy has a great reputation as a domain name registrar, their hosting services are abysmal. A prime example of this was that GoDaddy did not allow mod_rewrite nor access to YOUR .htaccess - I hope that this has changed but have heard nothing about this since I resigned (and the SitePoint was forum restructured).



Hi Dk,

Thank you for your thoughts and for help getting me started. In turns out that I did want the wildcard subdomain, something that my host allows (I’m using Cloudways as the host and GoDaddy as my domain name registrar). I’ve now added the wildcard subdomain on Cloudways, and have added an A record with *.my_domain.com on GoDaddy. I’m sure that I’ll have to wait a bit for my changes to propagate.

In the meantime, (and assuming that I did the above correctly!), it would be great to get a better handle on the .htaccess portion. From what you said:

“the typical setup is for the subdomain to be in a subdirectory of the
main domain so that it bypasses - and cannot access - the main domain’s

If this is the case, then if I allow the user the domain cool_user1.my_domain.com, then would I (via PHP):

  1. Create a folder cool_user1
  2. Create an htaccess in the folder with the same .htaccess that I have in my root? (ie to run everything through my main index.php)

There would be a lot of repeated files if I did it this way. But, if I took your recommendation (redirect to the main domain’s Document Root), then wouldn’t the url in the browser change to www.my_domain.com instead of looking like cool_user1.my_domain.com?

Your additional thoughts would be appreciated.

Hi kreut,

Whoops! Sorry for mangling your handle before.

If Cloudways is providing cPanel, I’d recommend that you leave GoDaddy out of this and simply add the wildcard subdomains via cPanel.

Unfortunately, if you allow users to upload to “their account” on your server, then it’s likely that they will use some files with identical names and the “collision” between accounts (using the main domain) will be catastrophic. If each is “jailed” in their own subdirectory, then you will not have that problem (the problem will simply be that none of your users will be able to access index.php in your main domain’s DocumentRoot - your #2 will fail).

Finally, to your last question, the URL will not change because the DocumentRoot for the subdomain(s) (all of them) is the same as for the main domain.

In other words, I don’t see a way out of the box you’ve painted yourself into. Sorry.



Hi Dk,

I have to apologize because I think that I’m not clearly expressing what I hope to do (and no worries about the name mangling!). I’m not actually allowing users to really upload to “their account”, I just want the customization to “look that way”. In other words, say you sign up for my site and get the custom domain name “bobs_cool_company” via a “Custom Domain Name” form. Then, Bob feels good about the fact that in the address bar he has his own “custom domain”. In other words, he can go to:


and Mike, with another cool company, can go to:


However, behind the scenes, in both situations, they’ll go to the same script:

www.my_domain/login (where my_domain is my site’s domain name).

And, note that once the user is logged in, I can prepend bobs_cool_company to all of my URL’s so that they all “look” customized…

Does this make more sense? And, would I still be trapped in this situation?

Hi kreut,

Looking back, I don’t see your words saying that your clients would upload to their own account. My bad, not yours.

So long as you are not allowing clients to upload AND your wildcard subdomain setup allows you to “redirect” to your main domain’s DocumentRoot, there shouldn’t be a problem. There should be a way for them to login to their “account” and use your PHP code to pull {whatever} from your database for any client-specific content.

That makes sense to me (and reminds me of the sessions I used ages ago to allow “staff” to manage specific content [stored in a database] on a club website).




Great! Now that I know it’s possible and I have at least a sense of the implementation, I can begin coding.



This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.