On my small new site I wish to have dynamic subdomains. I am attempting to make it to ensure that the subdomains make use of the same web root because the primary domain, all within single CodeIgniter installation. For instance, subdomain.example.com would result in example.com/subdomain, that is really example.com/index.php/subdomain.

I have already the DNS setup but I am getting swept up around the .htaccess.

VirtualDocumentRoot /var/www/crashworks/public/%-3+ May be the line from the sites-available configuration only for completeness. This may also cause the problem.

The result from the linked htaccess is the fact that when moving to the subdomain, it will get swept up within an infinite loop. (Error log after one request.) It is the same effect for www., that ought to just resolve towards the primary domain.

Have you try

RewriteEngine On

RewriteCond % !^www.example.com$ [NC]

RewriteCond % ^([a-z0-9]+).example.com$ [NC]

RewriteRule ^/(.*)$ index.php?url=%1&path=$1 [L,QSA]

Or something like that such as this?