-1

I have the domain www.mysite.com. This is what I ultimately want to do with it:

  1. On the site www.mysite.com, there will be a marketing website for my website/product (I'll call it the "software"), and a registration form. When registering, a customer specifies what subdomain they want to use, so say their company is XYZ Company, they would choose a subdomain of "xyz".

  2. Somehow, the url xyz.mysite.com is then able to run the code for my software.

  3. My software will inspect the domain name for each request, and extracts the subdomain value, i.e. "xyz". It uses this to set the connection string, i.e. to use database "xyz", and so that customer gets access to his data.

That's essentially it. A couple of things, though:

  1. I only want to have 1 copy of the code. All the subdomains should effectively "rewrite" the request to this central copy of the code, as the code will be identical across clients/subdomains.

  2. Ideally, although this is not essential, I hoped I would be able to 'wildcard' the A record (or CNAME record, or whatever), so that I didn't need to make any further DNS modifications whenever a client registered - i.e. EVERY & ANY value in the subdomain, would rewrite to the single code folder. I would check when the client requests the login page if that subdomain had been registered, and return 404 if not.

How do I achieve this? What combination of DNS records or aliases or subdomains do I need?

Sean
  • 123
  • 6

1 Answers1

2

You don't mention what web server you intend to use, but high level what you need to do is:

  1. Add an A record of *.mysite.com pointing to the IP address of your server. This is a standard record type and all provders support it. (Here is an example with GoDaddy https://uk.godaddy.com/help/setting-up-wildcard-dns-3301)
  2. Ensure that the default virtualhost in your web server is the one that serves up your site. This virtualhost will catch any traffic requesting an address not specified elsewhere. (Here is an example for Apache https://httpd.apache.org/docs/2.2/vhosts/examples.html#default)
  3. In whatever language you are writing the site in, make use of the data passed from the web server to your code about the address (hostname) used in the HTTP request. This is how you differentiate between your client sites. (Here is a PHP example https://stackoverflow.com/questions/5128474/php-serverserver-name-correct-use)
SimonJGreen
  • 3,195
  • 5
  • 30
  • 55