简体   繁体   中英

How to shorten urls in codeigniter using .htaccess?

I want to know if there is any way to shorten urls in a codeigniter using .htaccess. Like for example I have example.com/user/account/settings, I would like to shorten the url to example.com/settings. In the same way we remove index.php from the address bar, is there a way to remove more items from the same?

It's done by routes.php file in your CodeIgniter application folder. Documentation .

For your example it would be really easy, just add a line to the file:

$route['settings'] = 'user/account/settings';

By default, the index.php file will be included in your URLs: eg

example.com/index.php/news/article/my_article

You can easily remove this file by using a .htaccess file with some simple rules. Here is an example of such a file, using the "negative" method in which everything is redirected except the specified items:

RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]

In the above example, any HTTP request other than those for index.php, images, and robots.txt is treated as a request for your index.php file.

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