Codeigniter URL Rewriting
mostly we need to rewrite URLs to provide user friendly URLs of projects.
In CodeIgniter its much simple rather than manual writing HTAccess Rules.
Suppose you have :
- Controller (users)
- Function (index) list of all users
- Function (add) add user
- Function (view) view user
- Function (update) update user information
- Function (delete) delete user
Normally URLs will be :
But you want that URLs should be:
You do not need to add HTAccess rules in CodeIgnitor.
Just go to /application/config/routes.php
Aprx line 42
add following lines:
- $route[‘users’] = “users/index/”;
- $route[‘add-user’] = “users/add/”;
- $route[‘view-user’] = “users/view/”;
- $route[‘update-user’] = “users/update/”;
- $route[‘delete-user’] = “users/delete/”;
Now you can update your hyperlinks and rewrite rules will be done.
You open path www.example.com/add-user/
it will be opened www.example.com/users/add/