Author

Topic: [SOLVED] mod_rewrite / codeigniter / wildcard subdomains (Read 5743 times)

hero member
Activity: 576
Merit: 514
Closed, but anyway, tip sent. It wasn't related to the solution, but thanks very much for taking the time to check it out.


The solution was to have an extra .htaccess file under each subdomain, like a normal codeigniter installation should, and have the 2 different mod_rewrites in different .htaccess files... one in the main sub folder, and then one in each application, doing the codeigniter thing.
Thanks. I started to play around to see if I could stuff it into a single htaccess, but it's probably easier that way.
hero member
Activity: 630
Merit: 500
Maybe it's because of your first '[L]' flag?
It's used to stop processing the rule set.
So your subdomain rewrite matches and then the rewrite engine exits.

Closed, but anyway, tip sent. It wasn't related to the solution, but thanks very much for taking the time to check it out.


The solution was to have an extra .htaccess file under each subdomain, like a normal codeigniter installation should, and have the 2 different mod_rewrites in different .htaccess files... one in the main sub folder, and then one in each application, doing the codeigniter thing.
hero member
Activity: 630
Merit: 500
Removing that resulted in 404 on the various home pages. http://abc.domain.com/
hero member
Activity: 576
Merit: 514
Maybe it's because of your first '[L]' flag?
It's used to stop processing the rule set.
So your subdomain rewrite matches and then the rewrite engine exits.
hero member
Activity: 630
Merit: 500
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:

Code:
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:

Code:

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:

Code:
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=178
http://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.
Jump to: