Bitcoin Forum
December 16, 2017, 11:18:34 PM *
News: Latest stable version of Bitcoin Core: 0.15.1  [Torrent].
 
   Home   Help Search Donate Login Register  
Pages: [1]
  Print  
Author Topic: [SOLVED] mod_rewrite / codeigniter / wildcard subdomains  (Read 5652 times)
Cyberdyne
Hero Member
*****
Offline Offline

Activity: 630



View Profile
March 25, 2013, 01:37:59 PM
 #1

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:
<VirtualHost x.x.x.x:80>
DocumentRoot /var/www/domain.com/public_html
ServerName domain.com
ServerAlias www.domain.com
</VirtualHost>

<VirtualHost x.x.x.x:80>
DocumentRoot /var/www/domain.com/sub
ServerAlias *.domain.com
</VirtualHost>

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.
1513466314
Hero Member
*
Offline Offline

Posts: 1513466314

View Profile Personal Message (Offline)

Ignore
1513466314
Reply with quote  #2

1513466314
Report to moderator
1513466314
Hero Member
*
Offline Offline

Posts: 1513466314

View Profile Personal Message (Offline)

Ignore
1513466314
Reply with quote  #2

1513466314
Report to moderator
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction. Advertise here.
1513466314
Hero Member
*
Offline Offline

Posts: 1513466314

View Profile Personal Message (Offline)

Ignore
1513466314
Reply with quote  #2

1513466314
Report to moderator
1513466314
Hero Member
*
Offline Offline

Posts: 1513466314

View Profile Personal Message (Offline)

Ignore
1513466314
Reply with quote  #2

1513466314
Report to moderator
1513466314
Hero Member
*
Offline Offline

Posts: 1513466314

View Profile Personal Message (Offline)

Ignore
1513466314
Reply with quote  #2

1513466314
Report to moderator
Bitsky
Hero Member
*****
Offline Offline

Activity: 560


View Profile
March 25, 2013, 01:49:55 PM
 #2

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.

Bounty: Earn up to 68.7 BTC
Like my post? Feel free to drop a tip to 1BitskyZbfR4irjyXDaGAM2wYKQknwX36Y
Cyberdyne
Hero Member
*****
Offline Offline

Activity: 630



View Profile
March 25, 2013, 01:52:14 PM
 #3

Removing that resulted in 404 on the various home pages. http://abc.domain.com/
Cyberdyne
Hero Member
*****
Offline Offline

Activity: 630



View Profile
March 25, 2013, 02:04:28 PM
 #4

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.
Bitsky
Hero Member
*****
Offline Offline

Activity: 560


View Profile
March 25, 2013, 02:19:14 PM
 #5

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.

Bounty: Earn up to 68.7 BTC
Like my post? Feel free to drop a tip to 1BitskyZbfR4irjyXDaGAM2wYKQknwX36Y
Pages: [1]
  Print  
 
Jump to:  

Sponsored by , a Bitcoin-accepting VPN.
Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!