Reputation: 34229
Say I have a site hosted on example.com, now I want each of my registered user to get a personalized sub-domain, e.g Alice should normally gets alice.example.com as her sub-domain. While actually alice.example.com gets data from example.com/user/alice. How to implement this mechanism? I see lots of sites are working in this way. I wonder how they did it. Is it some kind of domain server configuration, web-server configuration, .htaccess rewrite or simply some tricks in the code?
If its redirecting, as I experimented, example.com and alice.example.com will get DIFFERENT IP addresses, if that, how rewrite works since when I request alice.example.com, the web browser takes me to a completely different site (IP address).
This has confused me for some time, I just can't figure it out myself, any help would be really appreciated.
[edit]: OK WAIT! I'm afraid I made a duplicate. Check this thread: Create subdomains on the fly with .htaccess (PHP)
Upvotes: 2
Views: 374
Reputation: 300855
I can tell how I did this on pastebin.com
Upvotes: 1
Reputation: 3599
Is it some kind of domain server configuration, web-server configuration, .htaccess rewrite or simply some tricks in the code?
It's probably a combination of the several techniques.
First layer would probably be a Wildcard DNS record on a DNS level so that any sub-domain can be used.
Next, server configuration or application logic is used to separate the content based on the accessed sub-domain. This can be Apache Alias directive or a Rewrite rule or logic in your application code.
Upvotes: 1
Reputation: 8038
Basically you need two parts:
1) Your Nameserver needs to support wildcards. So you would map *.mydomain.com to a single server. This will cause alice.mydomain.com and bob.mydomain.com to all go to the same server.
2) Then your server software should be able to map the hostname (=alice.mydomain.com) to your application and pass in the "alice" part as a parameter.
Depending in what framework/server software you use this should be quite easy.
HTH Alex
Upvotes: 1