Codeigniter and htaccess mod_rewrite |
[eluser]chris1986m[/eluser]
Hello, I'm little bit confused and not very good in writting htaccess files and because of that, i need your help! When I open follow link, i have to change the url to the base structure. So this is the link to my one page design www.test.com/testsystem/preview/index.php?/indexController But i want follow link in the url www.test.com/testsystem/preview/ - no index.php? - no controller - only the root directory And when i open follow www.test.com/testsystem/preview/index.php?/indexController/languageSwitch/fr I want follow url www.test.com/testsystem/preview/fr is this possible? Greetings
[eluser]Felipe Deitos[/eluser]
Start doing this in your htaccess Code: RewriteEngine On Maybe you will need to change /index.php/$1 to /testsystem/preview/index.php/$1 because your folder structure... This will probably eliminate the index.php from the url.. Then we need to understand your needs to do the next step. Remeber that the basic structure will always be www.site.com/class/function/id http://ellislab.com/codeigniter/user-gui.../urls.html (this may help) Cheers!
[eluser]chris1986m[/eluser]
Hi, thank you for the first code. I'll test it later. At the moment i only use one controller "indexController". This controller open the index.php view. I don't have modules or somethink else. webserver/directory/directory/view/default controller www.test.com/testsystem/preview/index.php?/indexController
[eluser]chris1986m[/eluser]
is it possible to open the default website www.test.com/testsystem/preview/index.php?/indexController only via www.test.com/testsystem/preview/
[eluser]Felipe Deitos[/eluser]
Yes it is, just do the code i posted before =D Test and you will see it!
[eluser]Mr. Pickle[/eluser]
Set this controller to be the default_controller in /config/routes.php Then this controller will always be used for requests to / (root) Should be something like this Code: $routes['default_controller'] = 'indexController'; I think it's also good to name your controllers more in line with the CodeIgniter convention, which is uppercase (Indexcontroller) and if preferred with underscore to seperate words (Index_controller) Of course as long as it works your free to name it how you like For any other routes you can make routes in the routes.php config-file. e.g: Code: $routes['/whatever'] = 'indexController/whatever'
[eluser]chris1986m[/eluser]
Hi, sooo i test it and have to say that i'm to stupid for this.... Codeigniter is installed into follow root direction: www.test.com/testsystem/preview/ Application www.test.com/testsystem/preview/application CSS www.test.com/testsystem/preview/css/main.css JS www.test.com/testsystem/preview/js/main.js htaccess in root www.test.com/testsystem/preview/.htaccess index.php in root www.test.com/testsystem/preview/index.php view (my complete one page html5 design frontend) www.test.com/testsystem/preview/application/views/index.php Is it possible to put the css and js files in the application or is the root directory the best solution? Please check my configs, maybe there is a mistake... Code: $config['base_url'] = 'www.test.com/testsystem/preview/'; Code: $route['default_controller'] = 'start'; Code: $autoload['libraries'] = array('session'); Code: <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); The language switch are only two buttons with follow href: Code: href="http://www.start.com/testsystem/preview/index.php?/indexController/languageSwitch/de" That was all. But why i have to say index.php? and not index.php. Thanks for all your help! Greets
[eluser]Mr. Pickle[/eluser]
First of all, if you installed the .htaccess correctly you don't have to use index.php at all. The purpose of the .htaccess file (like Felipe posted) is to be able to remove the index.php (including the ?) from the urls. This also corresponds with the fact that you in your config file have an empty $config['index_page'] instead of $config['index_page'] = 'index.php' To explain why you need the ?, this is because CodeIgniter runs on the bootstrap file index.php (meaning all requests go through this one index.php file. The actual paths after index.php should therefore by url parameters. The .htaccess file simulates the same situation. ---- I would recommend to put the application folder outside the webroot (to prevent access over the web) The index.php (bootstrap file), .htaccess and the assets (css, js, images) of course within the webroot. this means:
[eluser]chris1986m[/eluser]
Hi guys, it works.... i dont know why but it works! i think there was a little mistake in my code, but now its fine. Thanks a lot! Greets |
Welcome Guest, Not a member yet? Register Sign In |