Welcome Guest, Not a member yet? Register   Sign In
Multiple Applications
#1

[eluser]Unknown[/eluser]
Hey,

I'm trying to make multiple applications on one install of CodeIgniter. I've made it so my directory is like this:

Code:
system
     - application
          - myfirstapp
          - mysecondapp
myfirstapp.php
mysecondapp.php
index.php

and I've changed the application path in myfirstapp.php and mysecondapp.php. The problem I'm having is the url is now ../ci/myfirstapp.php/controller_name. When I would like it to be ../ci/myfirstapp/controller_name.

Can anyone help me out with this please?
#2

[eluser]RobertB.[/eluser]
take the system folder and put it in the www directory
www/system you can name the system folder whatever you want
then take the application folder and also name it whatever you want and also put it in the www directory

wamp/www/system
wamp/www/application

then all you have to do is in the main application index change this
Code:
$system_folder = "../system folder";
$application_folder = "../application folder";

in my case
Code:
$system_folder = "../system";
$application_folder = "../mysite";

Hope it help
#3

[eluser]pickupman[/eluser]
You would need to use a .htaccess file to rewrite url's. You will just need to make sure there would be no name collisions between subfolders and controller names. How about:
Code:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^myfirstapp/(.*)$ myfirstapp.php/$1
RewriteRule ^mysecondapp/(.*)$ mysecondapp.php/$1
RewriteRule ^(.*)$ index.php/$1 [L]

Haven't tried this yet though.
#4

[eluser]pickupman[/eluser]
Just tried this on a subfolder that I have the same setup on.
Code:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^myfirstapp/(.*)$ myfirstapp.php/$1 [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^mysecondapp/(.*)$ mysecondapp.php/$1 [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

You will need to edit your application/config.php to match the urls properly. I am using a the same site assets (css/js/images) that are in the same level as index.php. So I need each app to generate links like http://site/ci/myfirstapp/controller and have css links generated like
http://site/ci/(asset url).

In application/myfirstapp/config/config.php
Code:
$config['base_url'] = "http://".$_SERVER['HTTP_HOST']."/ci/";
$config['index_page'] = "myfirstapp/";

Just change index_page accordingly for each app.
#5

[eluser]Unknown[/eluser]
Thanks. I've changed my .htaccess to:

Code:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^myfirstapp/(.*)$ myfirstapp.php/$1 [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

and I've changed my config.php. However when I go to www.mysite.com/ci/myfirstapp/controller I get "404 Page Not Found. The page you requested was not found." but www.mysite.com/ci/myfirstapp.php/controller still works.

What am I doing wrong?
#6

[eluser]pickupman[/eluser]
Try and capitalize the word on in the first line you may also need to add RewriteBase /ci/ as your second line.
#7

[eluser]Greffer[/eluser]
Alright, I've tried everything on this thread, however, I did still get a 404 error.

Assuming my file structure is

Code:
system
applications
     - myfirstapp
     - mysecondapp
myfirstapp.php
mysecondapp.php

And in order to access myfirstapp

http://example.com/myfirstapp.php

And mysecondapp

http://example.com/mysecondapp.php

What exactly do I add in the .htaccess in order to hide the .php extensions so

http://example.com/myfirstapp.php/welcome = http://example.com/myfirstapp/welcome

And

http://example.com/mysecondapp.php/welcome = http://example.com/mysecond/welcome
#8

[eluser]pickupman[/eluser]
@Greffer

Is you application folder actually applications or is that a typo? It should be application unless you have changed this in your index.php. Do the URL's work when you use .php?

Two other things to check.
1. Is mod_rewrite/.htaccess enabled or allowed for your server? Can you rewrite other urls? Try writing something explicit.
2. Try changing the last line of the RewriteRule to include a question mark as some server environments need it.
Code:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^myfirstapp/(.*)$ myfirstapp.php?/$1 [L]
#9

[eluser]Greffer[/eluser]
I re-named the folder to "applications"

Also, I believe .htaccess is allowed as it does affect my URLs, I can see them

And I tried adding the lines of code into my .htaccess, but to no avail.
#10

[eluser]pickupman[/eluser]
Messed around for this for a quite awhile. Here's the cleanest solution. Create subdirectories in your root folder for each application
/system
/myfirstapp
/mysecondapp
index.php

Next copy the application folder into each of the subfolders in root along with a copy of a index.php file. Folder structure is now.
/system
/myfirstapp
/application
index.php
/mysecondapp
/application
index.php
index.php

Copy into each myapp subfolder a .htaccess file with contents
Code:
RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]

File structure now is
/system
/myfirstapp
/application
index.php
.htaccess
/mysecondapp
/application
index.php
.htaccess
index.php

Then you need to open each index.php file in each of your apps folders and change the system folder.
Code:
$system_path = '../system';

This tells the application to look up into the root folder for CI. The only other tidbit is to add a .htaccess rule in your root folder to redirect a request without any uri segments
(ie http://www.example.com/ => http://www.example.com/myfirstapp/) The problem with trying to use clean URLs by removing .php, the URI class is passing the wrong segments to the Router class. If you extend the URI class to change the offset of the URI, then the Router class can't find the controllers properly.




Theme © iAndrew 2016 - Forum software by © MyBB