Welcome Guest, Not a member yet? Register   Sign In
Multiple applications, one index.php
#1

[eluser]DarKDinDoN[/eluser]
Hello !

I'm dealing with the multiple apps and only one index.php ...

Here is the server's root folder :

Code:
./system/
./app_foo/
./app_bar/
./app_default/
./index.php
./.htaccess

and my .htaccess to avoid the index.php :

Code:
RewriteEngine On

RewriteBase /

Options +FollowSymLinks -Indexes

RewriteCond %{HTTP_HOST} ^example.com\.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]

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

And in the index.php, I manage to load the right app folder depending on the first url segment :

Code:
$url= $_SERVER['REQUEST_URI'] ;
   $app_resquested = explode("/", $url);

    switch ($app_resquested[1]) {
        case "foo":
            $application_folder = "../applications/app_foo";
            break;
        case "bar":
            $application_folder = "../applications/app_bar";
            break;
        default:
            $application_folder = "../applications/app_default";
    }

So, if I run :

Code:
http://www.example.com/     ---> should load the default app
http://www.example.com/foo  ---> should load the foo app
http://www.example.com/bar  ---> should load the bar app


The right apps are displayed, but for the foo and bar apps, I get a CI 404 error ... did I miss something ?
#2

[eluser]John_Betong[/eluser]
To find your errors I would be tempted to include this script in your index.php file to see what is changing:

Code:
echo '<pre>';
    print_r($_SERVER);
echo '<pre>';
&nbsp;
&nbsp;
&nbsp;

Instead of using .htaccess file I use a separate PHP file to:

1. start the session with session_start()
2. reset $_SESSION[‘_MENU_’]
3. select a new $_SESSION[‘_MENU_’]
4. redirect to index.php
5. test for the $_SESSION[‘_MENU_’] and set index.php -> $application_path

./index.php file.
$application_folder = isset($_SESSION['_MENU_']) ? $_SESSION['_MENU_'] : "ci_jokes";

The separate PHP file only requires calling once and from then until the session expires the _MENU_ application is used/
&nbsp;
&nbsp;
&nbsp;
#3

[eluser]DarKDinDoN[/eluser]
Thanks John_Betong,


I tried to display the server vars but nothing wrong...

CI logs indicate that everything is going right and that it loads the error route as it should do ... :grrr:

Can you post an example of your index.php and php session file ?
#4

[eluser]John_Betong[/eluser]
Here we go Smile

http://johns-jokes.com/this-is-a-test-to...-works.php

Code:
&lt;?php /* http://johns-jokes.com/this-is-a-test-to-see-if-it-works.php /*
session_start();
$_SESSION['_MENU_'] = 'ci_jokes';
if(0)
{
echo '<pre>';
  print_r($_SESSION);
echo '</pre>';
}
header('Location: ./index.php');
// not required ?&gt;


// index.php
...
...
$application_folder = isset($_SESSION['_MENU_']) ? $_SESSION['_MENU_'] : "ci_jokes";
...
...
&nbsp;
You can also check my http://johns-jokes.com/_menu.php
Unfortunately none of the menu links work due to a recent upgrade to CI_2_0-Reactor
&nbsp;
&nbsp;
// just back from my local, hope this works
#5

[eluser]Spir[/eluser]
The other apps are loading 404 because they didn't find the default controller or your base_url is not properly set. What did you put in your config for those website?
I'm gesssing they load controllers foo & bar. Or?
#6

[eluser]DarKDinDoN[/eluser]
@Spir : The default foo & bar controllers are properly set. But not with a foo or bar controller ...

@John_Betong : The sessions are not working for me as well ...

Thanks for you replies Wink
#7

[eluser]Spir[/eluser]
[quote author="DarKDinDoN" date="1296581185"]@Spir : The default foo & bar controllers are properly set. But not with a foo or bar controller ...

@John_Betong : The sessions are not working for me as well ...

Thanks for you replies Wink[/quote]Ok but what's in your config file?
Base url?
#8

[eluser]DarKDinDoN[/eluser]
Base url is set to http://www.example.com/ ... I can't let this var empty because it would break my entire app (links, images ...)

If I let it empty, my base url would be:
Code:
http://www.example.com/foo/

but my assets are not located in:

Code:
http://www.example.com/foo/assets/

but in:

Code:
http://www.example.com/assets/

and I won't be able to use img, anchor functions anymore ...
#9

[eluser]Spir[/eluser]
[quote author="DarKDinDoN" date="1296582872"]Base url is set to http://www.example.com/ ... I can't let this var empty because it would break my entire app (links, images ...)[/quote]That's what I'm talking about.

If for instance : http://www.example.com/foo ---&gt; should load the foo app
You said the app is successfully loaded but a 404 is displayed. That app should be configured to
base_url : http://www.example.com/foo/

Otherwhise that app looks for a controller called "foo" which doesn't exists. So it display a 404.
Also you could hack this using hooks maybe or a specific route routine.
#10

[eluser]DarKDinDoN[/eluser]
Ok !

I understand now Smile

I let you know if it works ^^




Theme © iAndrew 2016 - Forum software by © MyBB