How to remove controller name from URL in CodeIgniter


In CodeIgniter or any MVC application, the regular URL structure is like which appear as  But sometimes we may want to omit the controller name here to make the url more beautiful like or even as best url.

This beautiful url can be achieve through the URI Routing of CodIgniter. In
For, use this code


application/config/route.php file, you’ve to write following code for

  $route['user/(:any)']             = "user/profile/$1";

For, use this code

  $route['(:any)']                  = "user/profile/$1";

If you have multiple parameters like

public function profile($username, $city)
     echo "You are ".$username." from ".$city;

Your route will be

  $route['(:any)/(:any)']                  = "user/profile/$1/$2";

If you want to use number in parameter instead of string like these examples, you need to use (:num) instead of (:any).

If you are looking for something like modifying URL, I hope this post may help you. If you’ve any further question, you can comment bellow.

Author: Ariful Haque

Software Engineer | Freelance Web Application Developer PHP, CodeIgniter, WordPress, JavaScript, jQuery, Ajax, Ubuntu, CentOS, Apache..

2 thoughts on “How to remove controller name from URL in CodeIgniter”

Leave a Reply

Your email address will not be published. Required fields are marked *