Mike Mike - 6 months ago 156x
PHP Question

CodeIgniter default controller in a sub directory not working

My default_controller in the routes configuration is set as "home.php".

I have a sub directory for my controllers, lets call it "folder". So if I visit http://mysite.com/folder/, the default controller "folder/home.php" should be called right?

However for some reason this doesn't work, I get a 404. Visiting http://mysite.com/folder/home or http://mysite.com/folder/home/index works as expected. In addition to this, the default controller works in the root directory (http://mysite.com loads home.php).

Any ideas, has anyone else experienced this? I can't get my head around it - it would appear to be a CI issue but I can't find anybody else having the same problem.

The documentation, from the way I understand it at least, suggests that this should work fine: http://codeigniter.com/user_guide/general/controllers.html#subfolders

Setting the default controller to "folder/home.php" means that http://mysite.com/folder/ works fine as expected. Except for I want the default controller to just be "home.php" - whether in the root or in a sub directory, home.php within that directory should be loaded, as the documentation suggests.



For each sub-folder in your controllers folder you must specify a default controller in routes.php. The built in $route['default_controller'] will not work for sub-folders.

e.g: For setting the default controller for you folder sub-folder to home add the following to your /application/config/routes.php file:

$route['folder'] = "folder/home";

which means http://mysite.com/folder/ is the same as http://mysite.com/folder/home as URL.