简体   繁体   中英

how to shorten url in codeigniter using .htaccess?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM