Remove controller name from the URL in CodeIgniter

Example URL: http://www.raisul.net/controller/function/parameter

here “controller” is your controller name

“function” is controller function

“parameter” is parameter of pages function.

Now if we remove controller name from url,it should work , http://www.raisul.net/function/parameter

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


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

// here i removed controller name from url
$controller_exceptions = array(“function”); // here function 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′;
}
now run your project url like : http://www.raisul.net/function/parameter

.htaccess mod_rewrite for CodeIgniter

<IfModule mod_rewrite.c>
  RewriteEngine On
  # !IMPORTANT! Set your RewriteBase here and don't forget trailing and leading
  #  slashes.
  # If your page resides at
  #  http://www.example.com/mypage/test1
  # then use
  # RewriteBase /mypage/test1/
  RewriteBase /
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>

<IfModule !mod_rewrite.c>
  # If we don't have mod_rewrite installed, all 404's
  # can be sent to index.php, and everything works as normal.

  ErrorDocument 404 /index.php
</IfModule>