Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

creating sub-domains on signup

I'm building a site where businesses will be able to sign-up for there own account which should be located at http://businessname.example.com with the "businessname" changing each time.

I want to do this on a windows server (IIS 7) but am not sure how a go about it.

like image 835
Gaz Avatar asked Jul 21 '09 13:07

Gaz


People also ask

Can I create my own subdomain?

You can create a subdomain, by creating a new folder on your web space. This folder should contain an index file, which is the page that will be displayed when accessing the subdomain. You can create an unlimited amount of subdomains. Add a folder to the root of your web space.

Can you have 2 sub domains?

Subdomains are created to organize and navigate to different sections of your website. You can create multiple subdomains or child domains on your main domain. In this example, 'store' is the subdomain, 'yourwebsite' is the primary domain and '.com' is the top level domain (TLD).


3 Answers

via http://forums.asp.net/t/874598.aspx

If your DNS provider (ie. ISP) have "wildcard" option you could set *.mydomain.com -> myIP

Next step. Option #1 Make a script that creates 1 sites for each subdomain in IIS Option #2 Make a url_rewrite script that rewrites urls to correct folder on-the-fly.

option 2 is probably what you are looking for (and is STRONGLY recommended and preferred to option 1).

more info about url rewriting on iis7: http://learn.iis.net/page.aspx/460/using-url-rewrite-module/

The Microsoft URL Rewrite Module for IIS 7.0 provides flexible rules-based rewrite engine >that can be used to perform broad spectrum of URL manipulation tasks, including, but not >limited to:

  • Enabling user friendly and search engine friendly URL with dynamic web applications;
  • Rewriting URL’s based on HTTP headers and server variables;
  • Web site content handling;
  • Controlling access to web site content based on URL segments or request metadata.

the url rewriting option makes it easy to have hundreds of thousands of companies, their names can be read from the database and a url rewrite will handle the redirects. after that you can forget about it (for the most part) as it will keep on working for all the companies signing up in the future as well.

like image 73
b0x0rz Avatar answered Sep 30 '22 13:09

b0x0rz


First, you have to configure your DNS server to resolve *.example.com to the IP of your server.

Then, you have two choices:

  • Every time a new account is created, you add its host to the configuration of IIS, so it is bound to a directory. I'm not sure how to do this programmatically.
  • Every time a request is made to the server, you check the host, and redirect the client to the site corresponding to the host. It can either be an explicit redirect (the client arrives on http://businessname.domain.com/ and is redirected to http://sites.example.com/businessname/ ) or implicit (the client arrives on http://businessname.example.com/ and internally, the application located on a directory dedicated to businessname and treats the request.
like image 22
FWH Avatar answered Sep 30 '22 11:09

FWH


Generally, the better approach to this (if possible) is to not use Host Headers or separate IIS sites for each signup. Simply dedicate an IP address to that application that responds to all requests on Port 80 (or whatever port you use) and let your application detect the host header on request. This way, if you have 1,000 signups you don't end up with 1,000 "things" that need to be configured properly at the OS/services layer.

Alternatively if you just want the code, not sure what language you're looking at, but see below for C#...

http://forums.iis.net/t/1151463.aspx

like image 36
Brandon Avatar answered Sep 30 '22 13:09

Brandon