This is the most simple way I can ask this question as I have not fully understood what's going on, or what I am not doing right.

I'm having trouble with the url.

http://localhost/index.php/user is the same as http://localhost/ but http://localhost/index.php/user/something is not the same as http://localhost/something

How do I make http://localhost/something work?

Does it have to be http://localhost/user/something, how do I make that work?


Sorry, I'm just starting with CI and I can't find my answer anywhere, I've been at this for hours.

Accepted Answer

You need to understand how CodeIgniter's URLs work.

  • An URL consists of some segments. http://localhost/index.php/user/something/thing In this example user, something and thing are segments of the URL.

  • Segments of the URL indicate which controller and which method of that controller will run. http://localhost/index.php/user/something/thing In this example the method something from user controller is called and thing is passed to that method as a parameter.

  • The first segment of the URL indicates the controller.

  • The second segment of the URL indicates the method of that controller.

  • The following segments are sent to that method as parameters.

But there are some defaults.

  • If your URL is http://localhost/index.php/something, you have something specified as the controller, but because you have not specified any method, the default method which is index is called. So the above URL is the same as http://localhost/index.php/something/index

  • If your URL is http://localhost/index.php/, you don't have any segments specified (no controller and no method). So the default controller which is specified in application\config\routes.php is the loaded controller. Which method of that controller will be called? Of course the index method.

    --You can set the default controller by changing $route['default_controller'] = "site"; to what ever fits your application in application\config\routes.php's file.

  • If you want http://localhost/user/something to be the same as http://localhost/index.php/user/something, you have to create custom routes for your application. More info on that here.

Written by Yasser Souri
This page was build to provide you fast access to the question and the direct accepted answer.
The content is written by members of the community.
It is licensed under cc-wiki