Amazon I own oneminuteinfo.com domain and I would like configure my DNS and web server so that I can have multiple subdomains, each pointing to any document root I like. I know one way is to define all these subdomains in DNS configuration, and then define how my web server handles each of these subdomains, but this is too time consuming. I'd like an easier way!
How do you EASILY make multiple subdomains work? What configurations do you need in DNS manager and web server in order to enable multiple subdomains? Let's set up multiple subdomains for your domain in SECONDS!
Step 1: Set DNS Correctly
You need to tell your domain's DNS server that you would like all subdomains of your domain to point to your web server's IP address. For example let's say your web server's IP is 184.108.40.206. Then you should create an 'A' record with subdomain set to '*' less quotes and IP set to 220.127.116.11, as follows:
Subdomain or Host: *
Record Type: A
Depending on your domain host the way to do this may be different, but every DNS manager should allow you to create an 'A' record with some subdomain point to some IP address. For example in Go Daddy DNS manager you should create an A (Host) record with the following values:
Points to: 18.104.22.168
TTL: 1 Hour
This setting will make any subdomain of the domain oneminuteinfo.com point to 22.214.171.124.
However where would oneminuteinfo.com point to? oneminuteinfo.com has no subdomain and will NOT point to 126.96.36.199 UNLESS you explicitly create an A record for it. In GoDaddy DNS manager, for example, you should create an A (Host) record with the following values:
Points to: 188.8.131.52
TTL: 1 Hour
In GoDaddy DNS manager entering "@" for the host name is the same as entering your domain name, minus the "www". In another domain registration platform's DNS manager you may need to enter something else to mean the same thing, or just leave the text field empty. It totally depends on the domain registration system.
I know it's stupid that you need to create two A records in order to point oneminuteinfo.com and any subdomain of oneminuteinfo.com to 184.108.40.206, but that's just the way the cookie crumbles!
Let me know if you don't know how to do it!
Step 2: Configure Web Server Correctly
Now we simply tell our web server how to handle traffic that comes from each subdomain that we want to handle. The configurations depend on the web server you use. I use Apache2, and I have the following in my Apache2 configuration file which is /etc/apache2/site-available/all:
RewriteRule ^/(.*) http://www.oneminuteinfo.com/$1 [L,R=301]
This set of configurations should be very self explanatory. Requests that go to subdomain demo.oneminuteinfo.com would access /home/ubuntu/repository/demo directory. Requests that go to subdomain www.oneminuteinfo.com would access /home/ubuntu/repository/oneminuteinfo directory. Requests that go to any other subdomains (e.g. abc.oneminuteinfo.com) would go to /home/ubuntu/repository/trunk directory. Isn't it simple?
Suppose you don't have the configuration marked as BLOCK above then abc.oneminuteinfo.com might go to the first VirtualHost definition in your configuration file you have but it's really up to the web server how they want to handle this situation. This is my Apache web server's behavior. My Apache's version is 2.2.14 as shown below:
ubuntu@ip-10-16-4-7:~/repository$ apache2 -v
Server version: Apache/2.2.14 (Ubuntu)
Server built: Mar 5 2012 16:41:39
The last definition basically tells Apache to permanently redirect oneminuteinfo.com to www.oneminuteinfo.com. For example http://oneminuteinfo.com/2010/03/how-to-remove-virus-from-computer.html would 301 redirect to http://www.oneminuteinfo.com/2010/03/how-to-remove-virus-from-computer.html.
Any questions? Let me know!