Remove index.php from multiple application |
[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 But obviously this rewrite also my backend.php ![]() 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 ![]()
[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.
[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 ![]() 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.
[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
[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 ![]() 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
[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? ![]()
[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? ![]() Stefan, I'm sorry, I'm a noob on CI ![]() 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 And set this /application/frontend/config/routes.php: Code: $route['default_controller'] = "url"; // my default frontend controller url parser Is this way the correct way? ![]() Thank you
[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.
[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 ![]() So my actual situation is: Code: /system => CI framework And set my htaccess like that: Code: RewriteEngine on And my /application/config/routes.php: Code: $route['default_controller'] = "url"; // 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? ![]() ![]()
[eluser]CroNiX[/eluser]
You would just need to change this route: Code: $route['admin'] = 'admin'; Code: $route['admin'] = 'admin/welcome'; |
Welcome Guest, Not a member yet? Register Sign In |