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.

HOW TO REMOVE CONTROLLER NAME FROM THE URL IN CODEIGNITER?

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.

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

Read Also:  PHP cURL Http Authorization Pass Header Examples

Remove controller name from the URL in CodeIgniter

application/config/routes.php

$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: http://www.pakainfo.com/controller/getmembers/firstname

here “controller” is your controller name

Free Live Chat for Any Issue

“getmembers” is controller getmembers

“firstname” is firstname of pages getmembers.

Now if we remove controller name from url,it should work , http://www.pakainfo.com/getmembers/firstname

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

application/config/routes.php

$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 name.here you can mention as many as controller getmembers names.so that we can exclude controller name from the url

Read Also:  content limit in wordpress - How To Limit Words and Characters in content Wordpress?

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

now run your project url like : http://www.pakainfo.com/getmembers/firstname

Download

I hope you get an idea about Remove controller name from url.
I would like to have feedback on my infinityknow.com 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.