I have been searching for hours for the correct solution to this unsuccessfully so hopefully someone here might be able to help.
FOR 2 BTC Update: Bounty withdrawn, got it working. If anyone needs to know about this stuff just ask me because after tonight's effort I'm like some kind of expert on it now. Sometimes the quickest way to solve something is to clearly lay out a question for someone else.
I need to be able to have separate, 100% fully working codeigniter installations on wildcarded subdomains.
Example:
http://www.domain.com -> reads from /var/www/domain.com/public_html/index.php
http://abc.domain.com -> reads from /var/www/domain.com/sub/abc/index.php
http://xyz.domain.com -> reads from /var/www/domain.com/sub/xyz/index.php
http://*.domain.com -> reads from /var/www/domain.com/sub/*/index.php
- Sites must be able to be 100% separate codeigniter installations.
- Sites must work with codeigniter's mod_rewrite rules to remove 'index.php' from urls.
- Sites must correctly load controllers, eg http://abc.domain.com/faq should load domain.com/sub/abc/application/controllers/faq.php
Virtual hosts have been set up as follows:
DocumentRoot /var/www/domain.com/public_html
ServerName domain.com
ServerAlias www.domain.com
DocumentRoot /var/www/domain.com/sub
ServerAlias *.domain.com
I've tried putting this under /var/www/domain.com/sub/.htaccess:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^([^\.]+)\.domain\.com
RewriteCond /var/www/domain.com/sub/%1 -d
RewriteCond %{ENV:REDIRECT_STATUS} =""
RewriteRule ^(.*)$ /%1/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
The first part correctly redirects to the correct website depending on the subdomain used, but the second part (which codeignieter needs to remove the 'index.php' from urls and to find the controllers, does not work here.
I'm not interested in hardcoded solutions. Do not write literal strings such as 'abc' or 'xyz' anywhere. Also would rather not get into custom routing in the individual applications. (Unless it's just a 1 or 2 line regex sort of deal).
Nowhere I've looked on the web matches my situation exactly, but here's some stuff I've read:
http://snipplr.com/view/18613/http://codeblow.com/questions/codeigniter-and-rewriterule-problem/http://www.codepursuit.com/?p=178http://ellislab.com/forums/viewthread/89424/Ideally, someone will be able to figure all this out on their local machine and make a zip of the entire thing for me.
Thanks for reading.