Welcome Guest, Not a member yet? Register   Sign In
Remove index.php from multiple application
#1

[eluser]friimaind[/eluser]
Hi all,
I've setup two different application on my first CI project: front-end and back-end.
I have two different "index" files:
- index.php for the front-end application which points to /application/frontend/
- backend.php for the back-end application which points to /application/backend/

Now I would like to remove the index.php from the url, in the doc I've found this .htaccess:

Code:
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]

But obviously this rewrite also my backend.php Sad

How can I access my front-end application with http://www.mywebsitename.ext and my back-end application with http://www.mywebsitename.ext/backend ?

Thank you very much Smile
#2

[eluser]Stefan Hueg[/eluser]
Is it intended to have two separate applications?

If you just want that everything backend-related is accessible under /backend, just create a /backend - Folder in your application-folder and follow this scheme for your views etc. and use one single index.php.

If you want to let your application handle backend-requests differently (like: require a valid session on every single page access) you can just extend CI_Controller by creating a MY_Controller (check the documentation, extending core classes) and do those checks in the __construct() function.
#3

[eluser]friimaind[/eluser]
[quote author="Stefan Hueg" date="1336485047"]Is it intended to have two separate applications?

If you just want that everything backend-related is accessible under /backend, just create a /backend - Folder in your application-folder and follow this scheme for your views etc. and use one single index.php.

If you want to let your application handle backend-requests differently (like: require a valid session on every single page access) you can just extend CI_Controller by creating a MY_Controller (check the documentation, extending core classes) and do those checks in the __construct() function.[/quote]

HI Stefan Smile
Yes is intended to have two separate applications because it's a cms/eshop which doesn't have sharable controllers or models (except in rare cases).

I read the documentation http://ellislab.com/codeigniter/user-gui...hooks.html but I do not understand how I can have different models, controllers and views from the back-end and front-end.
I've searched on the forum (for example http://ellislab.com/forums/viewthread/94131/P15) and I would like to have two different application.
#4

[eluser]Stefan Hueg[/eluser]
Okay you say they are not sharing anything. Then you could build up the following file structure (just an example):

/var/www/frontend/application/controllers...
/var/www/backend/application/controllers...

And create an htaccess that is routing anything backend-related to your /var/www/backend/index.php, anything else to your /var/www/frontend/index.php

Or, which is easier, just create a subdomain for your backend.
I don't have a proper htaccess at hand at the moment and not plenty of time, but that'll do the trick
#5

[eluser]friimaind[/eluser]
[quote author="Stefan Hueg" date="1336486032"]Okay you say they are not sharing anything. Then you could build up the following file structure (just an example):

/var/www/frontend/application/controllers...
/var/www/backend/application/controllers...

And create an htaccess that is routing anything backend-related to your /var/www/backend/index.php, anything else to your /var/www/frontend/index.php

Or, which is easier, just create a subdomain for your backend.
I don't have a proper htaccess at hand at the moment and not plenty of time, but that'll do the trick[/quote]

Thank you Stefan Smile
I was hoping there was a simple rule to add to rewrite for the back end.
For example (unfortunately it does not work):

Code:
RewriteEngine on

# Rewrite front-end
RewriteCond $1 !^(index\.php|images|robots\.txt|backend\.php)
RewriteRule ^(.*)$ /index.php/$1 [L]

# Rewrite back-end
RewriteCond $1 !^(index\.php|images|robots\.txt|index\.php)
RewriteRule ^(.*)$ /backend.php/$1 [L]

#6

[eluser]Stefan Hueg[/eluser]
Well there is, but index.php is just a bootstrap file. Is this really what you have intended? Because, in my opinion, you won't gain anything. Tell me what are your ideas behind it? Smile
#7

[eluser]friimaind[/eluser]
[quote author="Stefan Hueg" date="1336486945"]Well there is, but index.php is just a bootstrap file. Is this really what you have intended? Because, in my opinion, you won't gain anything. Tell me what are your ideas behind it? Smile[/quote]

Stefan, I'm sorry, I'm a noob on CI Smile
My need is to have the following logical structure:

/system => framework CI
/application/backend => backend application (controllers, models, views etc...)
/application/frontend => frontend application (controllers, models, views etc...)

And this logical URL:
http://www.mywebsite.ext => front-end website (with http://www.mywebsite.ext/controller/action ...)
http://www.mywebsite.ext/admin => back-end (with http://www.mywebsite.ext/admin/controller/action ...)

But I have a controller on the front-end that parse every front-end request so I've write this htaccess:

Code:
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]

And set this /application/frontend/config/routes.php:

Code:
$route['default_controller'] = "url"; // my default frontend controller url parser
$route['404_override'] = '';
$route['admin/(:any)'] = 'backend/$1'; // is admin/something? so redirect to admin/something application
$route['admin'] = 'backend'; // is admin so redirect to admin application
$route['(:any)'] = 'url/urlHandler'; // all but admin requests

Is this way the correct way? Smile
Thank you
#8

[eluser]CroNiX[/eluser]
Personally, I just would have created an "admin" dir in the controllers dir (and models and views) and put all admin stuff there. Then you just need 1 index.php to run everything instead of 2 "separate" apps. I only create multiple apps if they are, well, different and not related. It seems a front end and back end for that front end are all part of the same codebase and would share a lot of code, so they should be the same app.
#9

[eluser]friimaind[/eluser]
[quote author="CroNiX" date="1336491478"]Personally, I just would have created an "admin" dir in the controllers dir (and models and views) and put all admin stuff there. Then you just need 1 index.php to run everything instead of 2 "separate" apps. I only create multiple apps if they are, well, different and not related. It seems a front end and back end for that front end are all part of the same codebase and would share a lot of code, so they should be the same app.[/quote]

Thank you.
I've googled a lot and I believe that I was very wrong indeed.
You're right Smile

So my actual situation is:

Code:
/system => CI framework
/application/controllers/ => controllers for frontend
/application/controllers/admin => controllers for admin
/application/models/ => models for frontend
/application/models/admin => models for admin
/application/views/ => views for frontend
/application/views/admin => views for admin

And set my htaccess like that:

Code:
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]

And my /application/config/routes.php:

Code:
$route['default_controller'] = "url"; // my url parser
$route['404_override'] = '';
$route['admin/(:any)'] = 'admin/$1'; // all admin/controller request to admin/controller..
$route['admin'] = 'admin';  // all admin request to admin
$route['(:any)'] = 'url/urlHandler'; // The method of my url parser

I'm almost at the solution:

http://www.mywebsite.ext/ => my url parser responds correctly
http://www.mywebsite.ext/welcome => my url parser responds correctly with welcome controller
http://www.mywebsite.ext/welcome/method => my url parser responds correctly with the method of welcome controller

http://www.mywebsite.ext/admin/welcome => my url parser responds correctly with welcome controller of admin
http://www.mywebsite.ext/admin/welcome/method => my url parser responds correctly with the method of welcome controller of admin

BUT I can't access the index() of admin controller when i go to http://www.mywebsite.ext/admin/ because responds the url parser.

I think I must rewrite /admin/ to the /admin/welcome/. Am I right?
IF I am right, how can I do it? Tongue

Smile
#10

[eluser]CroNiX[/eluser]
You would just need to change this route:
Code:
$route['admin'] = 'admin';
to
Code:
$route['admin'] = 'admin/welcome';




Theme © iAndrew 2016 - Forum software by © MyBB