how to remove controller name from url in codeigniter?

Today, We want to share with you how to remove controller name from url in codeigniter.In this post we will show you codeigniter remove controller from url, hear for remove controller name also from the URL we will give you demo and example for implement.In this post, we will learn about Remove “Public/Index.Php” From URL with an example.


For example, if our member_register page URL is like http://localhost/ci/home/member_register
here “home” is controller name and “member_register” is controller getmembers/method name.

Now if we remove controller name from URL, it should work, http://localhost/ci/member_register.

Read Also:  Insert Update Delete Query in SQL - SQL CRUD Query

Open application/config/routes.php file, and modify the code like below.

Remove controller name from the URL in CodeIgniter


$route['404_override'] = '';
$default_controller = 'home';
$route['default_controller'] = "$default_controller";
// here I have removed controller name from URL
$controller_exceptions = array("member_register"); // here member_register is controller getmembers name. You can add as many as controller getmembers names.
foreach($controller_exceptions as $v) {
  $route[$v] = "$default_controller/".$v;
  $route[$v."/(.*)"] = "$default_controller/".$v.'/$1';

Now the member_register page URL will work like: http://localhost/ci/member_register.

Example URL:

here “controller” is your controller name

“getmembers” is controller getmembers

“firstname” is firstname of pages getmembers.

Now if we remove controller name from url,it should work ,

Open application/config/routes.php file ,and changes the entire CI source code like this

Read Also:  Laravel delete foreign key Constraint Using Migration


$default_controller = "controller"; // default controller name
$route['default_controller'] = $default_controller;

// here i removed controller name from url
$controller_exceptions = array(“getmembers”); // here getmembers is controller getmembers you can mention as many as controller getmembers that we can exclude controller name from the url

foreach($controller_exceptions as $v) {
$route[$v] = “$default_controller/”.$v;
$route[$v.”/(.*)”] = “$default_controller/”.$v.’/$1′;

now run your project url like :

I hope you get an idea about Remove controller name from url.
I would like to have feedback on my blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.