How to remove controller name from URL in codeigniter?

How to hide controller and method name from url in codeigniter?

you can hide controller and method name from url using route.

<a href="<?php echo base_url()?>mycontroller">Get User Details</a>

$route['mycontroller'] = "admin/UserController/get_user_details";

when you click on this url its show mycontroller on the url bar.


For example, if your project url is like http://localhost:8080/ci/site/pages/Home
here “site” is your controller name

“pages” is controller function/method name and

“Home” is parameter of pages function.

Now if we remove controller name from url,it should work , http://localhost:8080/ci/pages/Home

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

/*------------------------------------------------------------------------------------------------------------*/

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

// here i removed controller name from url
$controller_exceptions = array("pages"); // here pages is controller function name.here you can mention as many as controller function names.so 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';
}

/*------------------------------------------------------------------------------------------------------------*/ // referece link :- http://www.iprogrammerindia.in/how-to-remove-controller-name-from-the-url-in-codeigniter/


How to remove mehotd name from url in codeigniter ?

For example, if your project url is like http://localhost:8080/ci/pages/Home
here pages is function name and Home is parameter of that function.

Now if we remove function name from url,it should work , http://localhost:8080/ci/Home

Open application/config/routes.php file ,and add the below lines

/*————————————————————————————————————*/
// here i removed method name from url

$method_exceptions = array("Home","Aboutus","Contactus"); //these are the function names in the controller.You can pass as many as to this array.

foreach($method_exceptions as $v) {
$route[$v] = "$default_controller/pages/$v";
}

/*————————————————————————————————————*/

How to remove index.php from url in codeigniter

Include the below lines in your codeigniter .htaccess file
/ci/ is path of your codeigniter folder , here i placed my codeigniter folder in C:/xampp/htdocs/


#----------------------------------------------------------------------

RewriteEngine On

RewriteBase /ci/

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^(.*)$ index.php/$1 [PT,L]

#----------------------------------------------------------------------





Previous Next


Trending Tutorials




Review & Rating

0.0 / 5

0 Review

5
(0)

4
(0)

3
(0)

2
(0)

1
(0)

Write Review Here