Reputation: 5
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?
Upvotes: 0
Views: 2224
Reputation: 3741
By default, the index.php file will be included in your URLs: e.g
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.
Upvotes: 1
Reputation: 12197
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';
Upvotes: 3