Codeigniter url path Codeigniter url path codeigniter codeigniter

Codeigniter url path


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.


http://localhost/something indicates that you are calling the index method of the Something controller class

http://localhost/user/something indicates that you are calling the something method in the User controller class.

Does that make sense?


In order to make http://localhost/something work, you need a controller called something with an index method. This would be the same as accessing http://localhost/something/index.

Alternatively, http://localhost/user/something implies that you have a user controller with a method called something.

Does that help at all?