• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
multiple applications, mod_rewrite and .htaccess

[eluser]Tom Vogt[/eluser]
After searching through the forums, experimenting and generally wasting at least an hour more than should be necessary, I've finally come up with a clean way to run multiple applications.

Directory structure:
- system
-- application
--- someapp
--- anotherapp
--- thirdapp

my .htaccess (in the top dir):
RewriteEngine on

RewriteCond $2 !^(index(|_[^\./]+)\.php|robots\.txt)
RewriteRule ^(someapp|anotherapp|thirdapp)(.*)$ /index_$1.php/$2 [L]

RewriteCond $1 !^(index(|_[^\./]+)\.php|images|common|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]

and then make new index.php files with filenames of "index_someapp.php", "index_anotherapp.php", etc. and the only difference among them is the setting of $application_folder (which should point to "application/someapp" etc.

Possible Improvements:
You could probably replace the list with a wildcard, but that should be a bit carefully constructed to prevent security problems, so I simply put the list in there, it's not as if I'd be changing the deployed apps all the time.

Just copying the index.php isn't necessarily the best solution, since only one line of 133 changes, so a bit of require_once() would greatly improve that part.

Other comments?


Check out:

Development test/sandbox site

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.