How to hide controller name in CodeIgniter url?
So here is a problem when we are using urls in Codeigniter and we want to short our urls for SEO Friendly URLS then we hide some portions of URL and short our urls.
Here are some examples to hide controller name in CodeIgniter url and short our urls.
1. First Example:
You can define a custom route in config/routes.php - for example:
$route['about'] = 'name_controller/about';
goes to http://example.com/name_controller/about
2. Second Example:
You can add an entry in the /system/application/config/routes.php file:
$route['about'] = "controller_name/about";
I did it like this: (config/routes.php)
Code: $route['((photos|blogs).+)'] = "$1";
$route['([a-zA-Z0-9_-]+)'] = "user/profile/$1";
it is ok correct solutions for common.
$route['default_controller'] = "xxx";
$route['home'] = "xxx/home";
$route['Collection/(:any)'] = "xxx/Collection/$1";
3. Third Example:
You can add below code in the /application/config/routes.php file:
$route['default_controller'] = "Home";
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;
$route['(?i)about'] = "Home/about";
$route['(?i)login'] = "Home/Login";
$route['(?i)products'] = "ProductController/ProductList";
$route['(?i)addproduct'] = "ProductController/AddProduct";
$route['(?i)editproduct'] = "ProductController/EditProduct";
$route['(?i)products/(:any)'] = "ProductController/ProductList/$1";