title: How to create dynamic subdomains in codeigniter with htaccess
body: <p>am using codeigniter, I want to set up .htaccess to make dynamic subdomains. And I cannot figure out how. 
  I am trying to create custom domain names using .htaccess</p>
  
  <p>Currently my URL looks like this:</p>
  
  <blockquote>
    <p><a href="http://www.example.com/public/stores/shop/products" rel="nofollow">http://www.example.com/public/stores/shop/products</a></p>
  </blockquote>
  
  <p>I need it to look like this:</p>
  
  <blockquote>
    <p><a href="http://www.shop.example.com/public/stores/products" rel="nofollow">http://www.shop.example.com/public/stores/products</a></p>
  </blockquote>
  
  <p>but it throws a 404?</p>
  
  <p>stores - controller name, 
  shop   - dynamic name</p>
  
  <p>The problem is that each shop should get a sub-domain automatically.Would be great if you could share the work around for the code &amp; the .htaccess</p>
  
  <p>I tried this code:</p>
  
  <pre><code>&lt;IfModule mod_rewrite.c&gt;
     Options +FollowSymLinks
     Options +Indexes
     RewriteEngine On
     RewriteBase /
  
     RewriteCond %{HTTP_HOST} !www.example.com$ [NC]
     RewriteCond %{REQUEST_URI} ^/$
     RewriteCond %{HTTP_HOST} ^(www.)?([a-z0-9-_]+).example.com [NC]
     RewriteRule (.*) /index.php/controller/function/%2 [P]
  
     RewriteCond $1 !^(index\.php|images|robots\.txt|css|js)
     RewriteRule ^(.*)$ /index.php/$1 [L]
  &lt;/IfModule&gt;
  </code></pre>
  
  <p>Thanks in advance.</p>