<p>I am looking to allow users to control of subdomain of an app I am toying with, much like Basecamp where it is <code>customusername.seework.com</code>.</p>

<p>What is required on the <code>DNS</code> end to allow these to be created dynamically and be available instantly. </p>

<p>And how do you recommend dealing with this in the logic of the site? <code>Htaccess</code> rule to  lookup the subdomain in the <code>DB</code>?</p>

[{'answer_id': 1185, 'author': 'Dave Ward', 'author_id': 60, 'author_profile': 'https://Stackoverflow.com/users/60', 'pm_score': 2, 'selected': False, 'text': "<p>The trick to that is to use URL rewriting so that <strong>name.domain.com</strong> transparently maps to something like <strong>domain.com/users/name</strong> on your server.  Once you start down that path, it's fairly trivial to implement.</p>\n"}, {'answer_id': 1187, 'author': 'lubos hasko', 'author_id': 275, 'author_profile': 'https://Stackoverflow.com/users/275', 'pm_score': 3, 'selected': False, 'text': '<p><strong>Don\'t worry about DNS and URL rewriting</strong></p>\n\n<p>Your DNS record will be static, something like:</p>\n\n<pre><code>*.YOURDOMAIN.COM A 123.123.123.123\n</code></pre>\n\n<p>Ask your DNS provider to do it for you (if it\'s not done already) or do it by yourself if you have control over your DNS records. This will automatically point all your subdomains (current and future ones) into the same HTTP server.</p>\n\n<p>Once it\'s done, you will only need to parse HOST header on every single http request to detect what hostname was used to access your server-side scripts on your http server.</p>\n\n<p>Assuming you\'re using ASP.NET, this is kind of silly example I came up with but works and demonstrates simplicity of this approach:</p>\n\n<pre><code>&lt;%@ Language="C#" %&gt;\n&lt;%\nstring subDomain = Request.Url.Host.Split(\'.\')[0].ToUpper();\nif (subDomain == "CLIENTXXX") Response.Write("Hello CLIENTXXX, your secret number is 33");\nelse if (subDomain == "CLIENTYYY") Response.Write("Hello CLIENTYYY, your secret number is 44");\nelse Response.Write(subDomain+" doesn\'t exist");\n%&gt;\n</code></pre>\n'}, {'answer_id': 1232, 'author': 'Mat', 'author_id': 48, 'author_profile': 'https://Stackoverflow.com/users/48', 'pm_score': 5, 'selected': True, 'text': '<p>The way we do this is to have a \'catch all\' for our domain name registered in DNS so that anything.ourdomain.com will point to our server.</p>\n\n<p>With Apache you can set up a similar catch-all for your vhosts.  The ServerName must be a single static name but the ServerAlias directive can contain a pattern.</p>\n\n<pre><code>Servername www.ourdomain.com\nServerAlias *.ourdomain.com\n</code></pre>\n\n<p>Now all of the domains will trigger the vhost for our project.  The final part is to decode the domain name actually used so that you can work out the username in your code, something like (PHP):</p>\n\n<pre><code>list( $username ) = explode( ".", $_SERVER[ "HTTP_HOST" ] );\n</code></pre>\n\n<p>or a RewriteRule as already suggested that silently maps user.ourdomain.com/foo/bar to www.ourdomain.com/foo/bar?user=user or whatever you prefer.</p>\n'}, {'answer_id': 1555232, 'author': 'Jamie', 'author_id': 188511, 'author_profile': 'https://Stackoverflow.com/users/188511', 'pm_score': 0, 'selected': False, 'text': '<p>I was looking to do something similar (<code>www.mysite.com/SomeUser</code>).</p>\n\n<p>What I did was I edited <code>404.shtml</code> to include this server side include (SSI) code:</p>\n\n<pre><code>&lt;!--#include virtual="404.php" -- &gt;\n</code></pre>\n\n<p>Then I created the file <code>404.php</code>, where I parsed the URL to check for a user\'s name and showed their info from the database.</p>\n'}]
['https://Stackoverflow.com/questions/1180', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/281/']