title: Wildcard subdomain .htaccess and Codeigniter
body: <p>I am trying to create the proper .htaccess that would allow me to map as such:</p>
  
  <pre><code>http://domain.com/                --&gt; http://domain.com/home 
  http://domain.com/whatever        --&gt; http://domain.com/home/whatever
  http://user.domain.com/           --&gt; http://domain.com/user 
  http://user.domain.com/whatever   --&gt; http://domain.com/user/whatever/
  </code></pre>
  
  <p>Here, someone would type in the above URLs, however internally, it would be redirecting as if it were the URL on the right.</p>
  
  <p>Also the subdomain would be dynamic (that is, <a href="http://user.domain.com" rel="nofollow">http://user.domain.com</a> isn't an actual subdomain but would be a .htaccess rewrite)</p>
  
  <p>Also /home is my default controller so no subdomain would internally force it to /home controller and any paths following it (as shown in #2 example above) would be the (catch-all) function within that controller.</p>
  
  <p>Like wise if a subdomain is passed it would get passed as a (catch-all) controller along with any (catch-all) functions for it (as shown in #4 example above)</p>
  
  <p>Hopefully I'm not asking much here but I can't seem to figure out the proper .htaccess or routing rules (in Codeigniter) for this.</p>
  
  <p>httpd.conf and hosts are setup just fine.</p>
  
  <p><strong>EDIT #1</strong></p>
  
  <p>Here's my .htaccess that is coming close but is messing up at some point:</p>
  
  <pre><code>RewriteEngine On
  
  RewriteBase /
  RewriteCond %{SCRIPT_FILENAME} !-d
  RewriteCond %{SCRIPT_FILENAME} !-f
  
  RewriteCond %{HTTP_HOST} ^([a-z0-9-]+).domain [NC]
  RewriteRule (.*) index.php/%1/$1 [QSA]
  
  RewriteCond $1 !^(index\.php|images|robots\.txt)
  RewriteRule ^(.*)$ /index.php/$1 [L,QSA]
  </code></pre>
  
  <p>With the above, when I visit: <a href="http://test.domain/abc/123" rel="nofollow">http://test.domain/abc/123</a> this is what I notice in $_SERVER var (I've removed some of the fields):</p>
  
  <pre><code>Array
  (
      [REDIRECT_STATUS] =&gt; 200
      [SERVER_NAME] =&gt; test.domain
      [REDIRECT_URL] =&gt; /abc/123
      [QUERY_STRING] =&gt; 
      [REQUEST_URI] =&gt; /abc/123
      [SCRIPT_NAME] =&gt; /index.php
      [PATH_INFO] =&gt; /test/abc/123
      [PATH_TRANSLATED] =&gt; redirect:\index.php\test\test\abc\123\abc\123
      [PHP_SELF] =&gt; /index.php/test/abc/123
  )
  </code></pre>
  
  <p>You can see the PATH_TRANSLATED is not properly being formed and I think that may be screwing things up?</p>