如何使用.htaccess缩短codeigniter中的url?

My project url is:

localhost/foldername/main(classname)/showmenu(methodname)/different_slugs // (e.g home,aboutus etc)

How to short this url to:

localhost/foldername/different_slugs //(e.g home,aboutus etc)

You can use routing of codeigniter. To know more on routing please click here.

You have to use .htaccess for that.

RewriteRule ^foldername/main/showmenu/(.*?)/$ localhost/foldername/$1

More info can be found here

You can use CodeIgniter's router to achieve this. Simply open the routes.php file in your application/config folder, and add this line:

$route['(:any)'] = 'main/showmenu';

This will redirect anything (and everything) to the specified address.

As for your .htaccess, all you need in that is:

RewriteEngine on
RewriteBase /foldername/ # in case you're working in a folder
RewriteCond %{REQUEST_URI} !\.(gif|jpe?g|png|css|js) [NC] # don't process files with these extensions - will be served normally
RewriteRule ^(.*)$ index.php/$1 [L] # redirect everything else to index