Codeigniter 3 - how to remove the function name from URL

Viewed 1176

My URL is:

example.com/controller/function/parameter
=> example.com/category/index/category_name

I need:

example.com/category/category_name

I have tried several solutions provided by Stackoverflow questions asked on this, but it´s not working. Either it redirects to home or a 404 page not found.

The options I have tried are:

$route['category'] = "category/index"; //1

$route['category/(:any)'] = "category/index"; //2

$route['category/(:any)'] = "category/index/$1";  //3

Another route is:

$route['default_controller'] = 'home';

The htaccess file:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|images|robots\.txt|css)
RewriteRule ^(.*)$ index.php/$1 [L]

In config file I have:

$config['url_suffix'] = '';
2 Answers
Related