<p>I've been Googling around for .htaccess redirection information, but nothing I find is quite what I'm looking for.</p>

<p>Basically, I want a solution that will take a site example.com and allow you to enter URL's like:</p>

<pre><code> 123.example.com
 ksdfkjds.example.com
 dsf38jif348.example.com
</code></pre>

<p>and this would redirect them to:</p>

<pre><code> example.com/123
 example.com/ksdfkjds
 example.com/dsf38jif348
</code></pre>

<p>So basically accept any subdomain and automatically redirect to a folder on the root of the domain with the name of that subdomain.</p>

Try something like this:
```
```
# If we're not on http://example.com
RewriteCond %{HTTP_HOST} .+\.example.com

# Add the host to the front of the URL and chain with the next rule
RewriteRule ^(.*)$ ${HOST}$1 [C,QSA]

# Make the host a directory
RewriteRule ^(.*)\.example\.com(.*)$ http://example.com/$1$2 [QSA]
```
```
You don't say what should happen to
http://foo.example.com/bar?moo
- I've made it go to
http://example.com/foo/bar?moo
Change the last line if that's not what you want.